xfrm4_state.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * xfrm4_state.c
  3. *
  4. * Changes:
  5. * YOSHIFUJI Hideaki @USAGI
  6. * Split up af-specific portion
  7. *
  8. */
  9. #include <net/ip.h>
  10. #include <net/xfrm.h>
  11. #include <linux/pfkeyv2.h>
  12. #include <linux/ipsec.h>
  13. #include <linux/netfilter_ipv4.h>
  14. #include <linux/export.h>
  15. static int xfrm4_init_flags(struct xfrm_state *x)
  16. {
  17. if (xs_net(x)->ipv4.sysctl_ip_no_pmtu_disc)
  18. x->props.flags |= XFRM_STATE_NOPMTUDISC;
  19. return 0;
  20. }
  21. static void
  22. __xfrm4_init_tempsel(struct xfrm_selector *sel, const struct flowi *fl)
  23. {
  24. const struct flowi4 *fl4 = &fl->u.ip4;
  25. sel->daddr.a4 = fl4->daddr;
  26. sel->saddr.a4 = fl4->saddr;
  27. sel->dport = xfrm_flowi_dport(fl, &fl4->uli);
  28. sel->dport_mask = htons(0xffff);
  29. sel->sport = xfrm_flowi_sport(fl, &fl4->uli);
  30. sel->sport_mask = htons(0xffff);
  31. sel->family = AF_INET;
  32. sel->prefixlen_d = 32;
  33. sel->prefixlen_s = 32;
  34. sel->proto = fl4->flowi4_proto;
  35. sel->ifindex = fl4->flowi4_oif;
  36. }
  37. static void
  38. xfrm4_init_temprop(struct xfrm_state *x, const struct xfrm_tmpl *tmpl,
  39. const xfrm_address_t *daddr, const xfrm_address_t *saddr)
  40. {
  41. x->id = tmpl->id;
  42. if (x->id.daddr.a4 == 0)
  43. x->id.daddr.a4 = daddr->a4;
  44. x->props.saddr = tmpl->saddr;
  45. if (x->props.saddr.a4 == 0)
  46. x->props.saddr.a4 = saddr->a4;
  47. x->props.mode = tmpl->mode;
  48. x->props.reqid = tmpl->reqid;
  49. x->props.family = AF_INET;
  50. }
  51. int xfrm4_extract_header(struct sk_buff *skb)
  52. {
  53. const struct iphdr *iph = ip_hdr(skb);
  54. XFRM_MODE_SKB_CB(skb)->ihl = sizeof(*iph);
  55. XFRM_MODE_SKB_CB(skb)->id = iph->id;
  56. XFRM_MODE_SKB_CB(skb)->frag_off = iph->frag_off;
  57. XFRM_MODE_SKB_CB(skb)->tos = iph->tos;
  58. XFRM_MODE_SKB_CB(skb)->ttl = iph->ttl;
  59. XFRM_MODE_SKB_CB(skb)->optlen = iph->ihl * 4 - sizeof(*iph);
  60. memset(XFRM_MODE_SKB_CB(skb)->flow_lbl, 0,
  61. sizeof(XFRM_MODE_SKB_CB(skb)->flow_lbl));
  62. return 0;
  63. }
  64. static struct xfrm_state_afinfo xfrm4_state_afinfo = {
  65. .family = AF_INET,
  66. .proto = IPPROTO_IPIP,
  67. .eth_proto = htons(ETH_P_IP),
  68. .owner = THIS_MODULE,
  69. .init_flags = xfrm4_init_flags,
  70. .init_tempsel = __xfrm4_init_tempsel,
  71. .init_temprop = xfrm4_init_temprop,
  72. .output = xfrm4_output,
  73. .output_finish = xfrm4_output_finish,
  74. .extract_input = xfrm4_extract_input,
  75. .extract_output = xfrm4_extract_output,
  76. .transport_finish = xfrm4_transport_finish,
  77. .local_error = xfrm4_local_error,
  78. };
  79. void __init xfrm4_state_init(void)
  80. {
  81. xfrm_state_register_afinfo(&xfrm4_state_afinfo);
  82. }
  83. #if 0
  84. void __exit xfrm4_state_fini(void)
  85. {
  86. xfrm_state_unregister_afinfo(&xfrm4_state_afinfo);
  87. }
  88. #endif /* 0 */