xfrm4_state.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. static int xfrm4_init_flags(struct xfrm_state *x)
  15. {
  16. if (ipv4_config.no_pmtu_disc)
  17. x->props.flags |= XFRM_STATE_NOPMTUDISC;
  18. return 0;
  19. }
  20. static void
  21. __xfrm4_init_tempsel(struct xfrm_selector *sel, const struct flowi *fl)
  22. {
  23. const struct flowi4 *fl4 = &fl->u.ip4;
  24. sel->daddr.a4 = fl4->daddr;
  25. sel->saddr.a4 = fl4->saddr;
  26. sel->dport = xfrm_flowi_dport(fl, &fl4->uli);
  27. sel->dport_mask = htons(0xffff);
  28. sel->sport = xfrm_flowi_sport(fl, &fl4->uli);
  29. sel->sport_mask = htons(0xffff);
  30. sel->family = AF_INET;
  31. sel->prefixlen_d = 32;
  32. sel->prefixlen_s = 32;
  33. sel->proto = fl4->flowi4_proto;
  34. sel->ifindex = fl4->flowi4_oif;
  35. }
  36. static void
  37. xfrm4_init_temprop(struct xfrm_state *x, const struct xfrm_tmpl *tmpl,
  38. const xfrm_address_t *daddr, const xfrm_address_t *saddr)
  39. {
  40. x->id = tmpl->id;
  41. if (x->id.daddr.a4 == 0)
  42. x->id.daddr.a4 = daddr->a4;
  43. x->props.saddr = tmpl->saddr;
  44. if (x->props.saddr.a4 == 0)
  45. x->props.saddr.a4 = saddr->a4;
  46. x->props.mode = tmpl->mode;
  47. x->props.reqid = tmpl->reqid;
  48. x->props.family = AF_INET;
  49. }
  50. int xfrm4_extract_header(struct sk_buff *skb)
  51. {
  52. const struct iphdr *iph = ip_hdr(skb);
  53. XFRM_MODE_SKB_CB(skb)->ihl = sizeof(*iph);
  54. XFRM_MODE_SKB_CB(skb)->id = iph->id;
  55. XFRM_MODE_SKB_CB(skb)->frag_off = iph->frag_off;
  56. XFRM_MODE_SKB_CB(skb)->tos = iph->tos;
  57. XFRM_MODE_SKB_CB(skb)->ttl = iph->ttl;
  58. XFRM_MODE_SKB_CB(skb)->optlen = iph->ihl * 4 - sizeof(*iph);
  59. memset(XFRM_MODE_SKB_CB(skb)->flow_lbl, 0,
  60. sizeof(XFRM_MODE_SKB_CB(skb)->flow_lbl));
  61. return 0;
  62. }
  63. static struct xfrm_state_afinfo xfrm4_state_afinfo = {
  64. .family = AF_INET,
  65. .proto = IPPROTO_IPIP,
  66. .eth_proto = htons(ETH_P_IP),
  67. .owner = THIS_MODULE,
  68. .init_flags = xfrm4_init_flags,
  69. .init_tempsel = __xfrm4_init_tempsel,
  70. .init_temprop = xfrm4_init_temprop,
  71. .output = xfrm4_output,
  72. .output_finish = xfrm4_output_finish,
  73. .extract_input = xfrm4_extract_input,
  74. .extract_output = xfrm4_extract_output,
  75. .transport_finish = xfrm4_transport_finish,
  76. };
  77. void __init xfrm4_state_init(void)
  78. {
  79. xfrm_state_register_afinfo(&xfrm4_state_afinfo);
  80. }
  81. #if 0
  82. void __exit xfrm4_state_fini(void)
  83. {
  84. xfrm_state_unregister_afinfo(&xfrm4_state_afinfo);
  85. }
  86. #endif /* 0 */