Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * xfrm4_state.c |
| 3 | * |
| 4 | * Changes: |
| 5 | * YOSHIFUJI Hideaki @USAGI |
| 6 | * Split up af-specific portion |
| 7 | * |
| 8 | */ |
| 9 | |
Herbert Xu | dd87147 | 2005-06-20 13:21:43 -0700 | [diff] [blame] | 10 | #include <net/ip.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | #include <net/xfrm.h> |
| 12 | #include <linux/pfkeyv2.h> |
| 13 | #include <linux/ipsec.h> |
Herbert Xu | 862b82c | 2007-11-13 21:43:11 -0800 | [diff] [blame] | 14 | #include <linux/netfilter_ipv4.h> |
Paul Gortmaker | bc3b2d7 | 2011-07-15 11:47:34 -0400 | [diff] [blame] | 15 | #include <linux/export.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | |
Herbert Xu | dd87147 | 2005-06-20 13:21:43 -0700 | [diff] [blame] | 17 | static int xfrm4_init_flags(struct xfrm_state *x) |
| 18 | { |
| 19 | if (ipv4_config.no_pmtu_disc) |
| 20 | x->props.flags |= XFRM_STATE_NOPMTUDISC; |
| 21 | return 0; |
| 22 | } |
| 23 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | static void |
David S. Miller | 73e5ebb | 2011-02-22 17:51:44 -0800 | [diff] [blame] | 25 | __xfrm4_init_tempsel(struct xfrm_selector *sel, const struct flowi *fl) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | { |
David S. Miller | 7e1dc7b | 2011-03-12 02:42:11 -0500 | [diff] [blame] | 27 | const struct flowi4 *fl4 = &fl->u.ip4; |
| 28 | |
| 29 | sel->daddr.a4 = fl4->daddr; |
| 30 | sel->saddr.a4 = fl4->saddr; |
| 31 | sel->dport = xfrm_flowi_dport(fl, &fl4->uli); |
Thomas Egerer | 8444cf7 | 2010-09-20 11:11:38 -0700 | [diff] [blame] | 32 | sel->dport_mask = htons(0xffff); |
David S. Miller | 7e1dc7b | 2011-03-12 02:42:11 -0500 | [diff] [blame] | 33 | sel->sport = xfrm_flowi_sport(fl, &fl4->uli); |
Thomas Egerer | 8444cf7 | 2010-09-20 11:11:38 -0700 | [diff] [blame] | 34 | sel->sport_mask = htons(0xffff); |
| 35 | sel->family = AF_INET; |
| 36 | sel->prefixlen_d = 32; |
| 37 | sel->prefixlen_s = 32; |
David S. Miller | 7e1dc7b | 2011-03-12 02:42:11 -0500 | [diff] [blame] | 38 | sel->proto = fl4->flowi4_proto; |
| 39 | sel->ifindex = fl4->flowi4_oif; |
Thomas Egerer | 8444cf7 | 2010-09-20 11:11:38 -0700 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | static void |
David S. Miller | 19bd624 | 2011-02-24 00:07:20 -0500 | [diff] [blame] | 43 | xfrm4_init_temprop(struct xfrm_state *x, const struct xfrm_tmpl *tmpl, |
| 44 | const xfrm_address_t *daddr, const xfrm_address_t *saddr) |
Thomas Egerer | 8444cf7 | 2010-09-20 11:11:38 -0700 | [diff] [blame] | 45 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | x->id = tmpl->id; |
| 47 | if (x->id.daddr.a4 == 0) |
| 48 | x->id.daddr.a4 = daddr->a4; |
| 49 | x->props.saddr = tmpl->saddr; |
| 50 | if (x->props.saddr.a4 == 0) |
| 51 | x->props.saddr.a4 = saddr->a4; |
| 52 | x->props.mode = tmpl->mode; |
| 53 | x->props.reqid = tmpl->reqid; |
| 54 | x->props.family = AF_INET; |
| 55 | } |
| 56 | |
Herbert Xu | 36cf9ac | 2007-11-13 21:40:52 -0800 | [diff] [blame] | 57 | int xfrm4_extract_header(struct sk_buff *skb) |
| 58 | { |
Eric Dumazet | b71d1d4 | 2011-04-22 04:53:02 +0000 | [diff] [blame] | 59 | const struct iphdr *iph = ip_hdr(skb); |
Herbert Xu | 36cf9ac | 2007-11-13 21:40:52 -0800 | [diff] [blame] | 60 | |
Herbert Xu | 732c8bd | 2008-03-26 16:51:09 -0700 | [diff] [blame] | 61 | XFRM_MODE_SKB_CB(skb)->ihl = sizeof(*iph); |
Herbert Xu | 36cf9ac | 2007-11-13 21:40:52 -0800 | [diff] [blame] | 62 | XFRM_MODE_SKB_CB(skb)->id = iph->id; |
| 63 | XFRM_MODE_SKB_CB(skb)->frag_off = iph->frag_off; |
| 64 | XFRM_MODE_SKB_CB(skb)->tos = iph->tos; |
| 65 | XFRM_MODE_SKB_CB(skb)->ttl = iph->ttl; |
Herbert Xu | 732c8bd | 2008-03-26 16:51:09 -0700 | [diff] [blame] | 66 | XFRM_MODE_SKB_CB(skb)->optlen = iph->ihl * 4 - sizeof(*iph); |
Herbert Xu | 36cf9ac | 2007-11-13 21:40:52 -0800 | [diff] [blame] | 67 | memset(XFRM_MODE_SKB_CB(skb)->flow_lbl, 0, |
| 68 | sizeof(XFRM_MODE_SKB_CB(skb)->flow_lbl)); |
| 69 | |
| 70 | return 0; |
| 71 | } |
| 72 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | static struct xfrm_state_afinfo xfrm4_state_afinfo = { |
| 74 | .family = AF_INET, |
Herbert Xu | 36cf9ac | 2007-11-13 21:40:52 -0800 | [diff] [blame] | 75 | .proto = IPPROTO_IPIP, |
Herbert Xu | 227620e | 2007-11-13 21:41:28 -0800 | [diff] [blame] | 76 | .eth_proto = htons(ETH_P_IP), |
Herbert Xu | 17c2a42 | 2007-10-17 21:33:12 -0700 | [diff] [blame] | 77 | .owner = THIS_MODULE, |
Herbert Xu | dd87147 | 2005-06-20 13:21:43 -0700 | [diff] [blame] | 78 | .init_flags = xfrm4_init_flags, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | .init_tempsel = __xfrm4_init_tempsel, |
Thomas Egerer | 8444cf7 | 2010-09-20 11:11:38 -0700 | [diff] [blame] | 80 | .init_temprop = xfrm4_init_temprop, |
Miika Komu | cdca726 | 2007-02-06 14:24:56 -0800 | [diff] [blame] | 81 | .output = xfrm4_output, |
Steffen Klassert | 43a4dea | 2011-05-09 19:36:38 +0000 | [diff] [blame] | 82 | .output_finish = xfrm4_output_finish, |
Herbert Xu | 227620e | 2007-11-13 21:41:28 -0800 | [diff] [blame] | 83 | .extract_input = xfrm4_extract_input, |
Herbert Xu | 36cf9ac | 2007-11-13 21:40:52 -0800 | [diff] [blame] | 84 | .extract_output = xfrm4_extract_output, |
Herbert Xu | 716062f | 2007-11-13 21:44:23 -0800 | [diff] [blame] | 85 | .transport_finish = xfrm4_transport_finish, |
Hannes Frederic Sowa | 628e341 | 2013-08-14 13:05:23 +0200 | [diff] [blame] | 86 | .local_error = xfrm4_local_error, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | }; |
| 88 | |
| 89 | void __init xfrm4_state_init(void) |
| 90 | { |
| 91 | xfrm_state_register_afinfo(&xfrm4_state_afinfo); |
| 92 | } |
| 93 | |
Adrian Bunk | 0742fd5 | 2005-08-09 19:35:47 -0700 | [diff] [blame] | 94 | #if 0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | void __exit xfrm4_state_fini(void) |
| 96 | { |
| 97 | xfrm_state_unregister_afinfo(&xfrm4_state_afinfo); |
| 98 | } |
Adrian Bunk | 0742fd5 | 2005-08-09 19:35:47 -0700 | [diff] [blame] | 99 | #endif /* 0 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | |