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> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | |
Herbert Xu | dd87147 | 2005-06-20 13:21:43 -0700 | [diff] [blame] | 16 | static int xfrm4_init_flags(struct xfrm_state *x) |
| 17 | { |
| 18 | if (ipv4_config.no_pmtu_disc) |
| 19 | x->props.flags |= XFRM_STATE_NOPMTUDISC; |
| 20 | return 0; |
| 21 | } |
| 22 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | static void |
| 24 | __xfrm4_init_tempsel(struct xfrm_state *x, struct flowi *fl, |
| 25 | struct xfrm_tmpl *tmpl, |
| 26 | xfrm_address_t *daddr, xfrm_address_t *saddr) |
| 27 | { |
| 28 | x->sel.daddr.a4 = fl->fl4_dst; |
| 29 | x->sel.saddr.a4 = fl->fl4_src; |
| 30 | x->sel.dport = xfrm_flowi_dport(fl); |
Al Viro | 8f83f23 | 2006-09-27 18:46:11 -0700 | [diff] [blame] | 31 | x->sel.dport_mask = htons(0xffff); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | x->sel.sport = xfrm_flowi_sport(fl); |
Al Viro | 8f83f23 | 2006-09-27 18:46:11 -0700 | [diff] [blame] | 33 | x->sel.sport_mask = htons(0xffff); |
Andreas Steffen | 79654a7 | 2008-11-04 14:49:19 -0800 | [diff] [blame] | 34 | x->sel.family = AF_INET; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | x->sel.prefixlen_d = 32; |
| 36 | x->sel.prefixlen_s = 32; |
| 37 | x->sel.proto = fl->proto; |
| 38 | x->sel.ifindex = fl->oif; |
| 39 | x->id = tmpl->id; |
| 40 | if (x->id.daddr.a4 == 0) |
| 41 | x->id.daddr.a4 = daddr->a4; |
| 42 | x->props.saddr = tmpl->saddr; |
| 43 | if (x->props.saddr.a4 == 0) |
| 44 | x->props.saddr.a4 = saddr->a4; |
| 45 | x->props.mode = tmpl->mode; |
| 46 | x->props.reqid = tmpl->reqid; |
| 47 | x->props.family = AF_INET; |
| 48 | } |
| 49 | |
Herbert Xu | 36cf9ac | 2007-11-13 21:40:52 -0800 | [diff] [blame] | 50 | int xfrm4_extract_header(struct sk_buff *skb) |
| 51 | { |
| 52 | struct iphdr *iph = ip_hdr(skb); |
| 53 | |
Herbert Xu | 732c8bd | 2008-03-26 16:51:09 -0700 | [diff] [blame] | 54 | XFRM_MODE_SKB_CB(skb)->ihl = sizeof(*iph); |
Herbert Xu | 36cf9ac | 2007-11-13 21:40:52 -0800 | [diff] [blame] | 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; |
Herbert Xu | 732c8bd | 2008-03-26 16:51:09 -0700 | [diff] [blame] | 59 | XFRM_MODE_SKB_CB(skb)->optlen = iph->ihl * 4 - sizeof(*iph); |
Herbert Xu | 36cf9ac | 2007-11-13 21:40:52 -0800 | [diff] [blame] | 60 | memset(XFRM_MODE_SKB_CB(skb)->flow_lbl, 0, |
| 61 | sizeof(XFRM_MODE_SKB_CB(skb)->flow_lbl)); |
| 62 | |
| 63 | return 0; |
| 64 | } |
| 65 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | static struct xfrm_state_afinfo xfrm4_state_afinfo = { |
| 67 | .family = AF_INET, |
Herbert Xu | 36cf9ac | 2007-11-13 21:40:52 -0800 | [diff] [blame] | 68 | .proto = IPPROTO_IPIP, |
Herbert Xu | 227620e | 2007-11-13 21:41:28 -0800 | [diff] [blame] | 69 | .eth_proto = htons(ETH_P_IP), |
Herbert Xu | 17c2a42 | 2007-10-17 21:33:12 -0700 | [diff] [blame] | 70 | .owner = THIS_MODULE, |
Herbert Xu | dd87147 | 2005-06-20 13:21:43 -0700 | [diff] [blame] | 71 | .init_flags = xfrm4_init_flags, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | .init_tempsel = __xfrm4_init_tempsel, |
Miika Komu | cdca726 | 2007-02-06 14:24:56 -0800 | [diff] [blame] | 73 | .output = xfrm4_output, |
Herbert Xu | 227620e | 2007-11-13 21:41:28 -0800 | [diff] [blame] | 74 | .extract_input = xfrm4_extract_input, |
Herbert Xu | 36cf9ac | 2007-11-13 21:40:52 -0800 | [diff] [blame] | 75 | .extract_output = xfrm4_extract_output, |
Herbert Xu | 716062f | 2007-11-13 21:44:23 -0800 | [diff] [blame] | 76 | .transport_finish = xfrm4_transport_finish, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | }; |
| 78 | |
| 79 | void __init xfrm4_state_init(void) |
| 80 | { |
| 81 | xfrm_state_register_afinfo(&xfrm4_state_afinfo); |
| 82 | } |
| 83 | |
Adrian Bunk | 0742fd5 | 2005-08-09 19:35:47 -0700 | [diff] [blame] | 84 | #if 0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | void __exit xfrm4_state_fini(void) |
| 86 | { |
| 87 | xfrm_state_unregister_afinfo(&xfrm4_state_afinfo); |
| 88 | } |
Adrian Bunk | 0742fd5 | 2005-08-09 19:35:47 -0700 | [diff] [blame] | 89 | #endif /* 0 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | |