diff options
author | Herbert Xu <herbert@gondor.apana.org.au> | 2007-11-14 00:40:52 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2008-01-28 17:53:45 -0500 |
commit | 36cf9acf93e8561d9faec24849e57688a81eb9c5 (patch) | |
tree | fd4fab84132f1784a23441e03c4a0b9aea6cc43a /include | |
parent | 29bb43b4ec4e625b0659186fc8a7c8f8b7c81982 (diff) |
[IPSEC]: Separate inner/outer mode processing on output
With inter-family transforms the inner mode differs from the outer
mode. Attempting to handle both sides from the same function means
that it needs to handle both IPv4 and IPv6 which creates duplication
and confusion.
This patch separates the two parts on the output path so that each
function deals with one family only.
In particular, the functions xfrm4_extract_output/xfrm6_extract_output
moves the pertinent fields from the IPv4/IPv6 IP headers into a
neutral format stored in skb->cb. This is then used by the outer mode
output functions to write the outer IP header. In this way the output
function no longer has to know about the inner address family.
Since the extract functions are only called by tunnel modes (the only
modes that can support inter-family transforms), I've also moved the
xfrm*_tunnel_check_size calls into them. This allows the correct ICMP
message to be sent as opposed to now where you might call icmp_send
with an IPv6 packet and vice versa.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'include')
-rw-r--r-- | include/net/xfrm.h | 51 |
1 files changed, 50 insertions, 1 deletions
diff --git a/include/net/xfrm.h b/include/net/xfrm.h index c9345fe3f8d2..138c1868be1d 100644 --- a/include/net/xfrm.h +++ b/include/net/xfrm.h | |||
@@ -257,6 +257,7 @@ extern int __xfrm_state_delete(struct xfrm_state *x); | |||
257 | 257 | ||
258 | struct xfrm_state_afinfo { | 258 | struct xfrm_state_afinfo { |
259 | unsigned int family; | 259 | unsigned int family; |
260 | unsigned int proto; | ||
260 | struct module *owner; | 261 | struct module *owner; |
261 | struct xfrm_type *type_map[IPPROTO_MAX]; | 262 | struct xfrm_type *type_map[IPPROTO_MAX]; |
262 | struct xfrm_mode *mode_map[XFRM_MODE_MAX]; | 263 | struct xfrm_mode *mode_map[XFRM_MODE_MAX]; |
@@ -267,6 +268,8 @@ struct xfrm_state_afinfo { | |||
267 | int (*tmpl_sort)(struct xfrm_tmpl **dst, struct xfrm_tmpl **src, int n); | 268 | int (*tmpl_sort)(struct xfrm_tmpl **dst, struct xfrm_tmpl **src, int n); |
268 | int (*state_sort)(struct xfrm_state **dst, struct xfrm_state **src, int n); | 269 | int (*state_sort)(struct xfrm_state **dst, struct xfrm_state **src, int n); |
269 | int (*output)(struct sk_buff *skb); | 270 | int (*output)(struct sk_buff *skb); |
271 | int (*extract_output)(struct xfrm_state *x, | ||
272 | struct sk_buff *skb); | ||
270 | }; | 273 | }; |
271 | 274 | ||
272 | extern int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo); | 275 | extern int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo); |
@@ -312,7 +315,18 @@ struct xfrm_mode { | |||
312 | * header. The value of the network header will always point | 315 | * header. The value of the network header will always point |
313 | * to the top IP header while skb->data will point to the payload. | 316 | * to the top IP header while skb->data will point to the payload. |
314 | */ | 317 | */ |
315 | int (*output)(struct xfrm_state *x,struct sk_buff *skb); | 318 | int (*output2)(struct xfrm_state *x,struct sk_buff *skb); |
319 | |||
320 | /* | ||
321 | * This is the actual output entry point. | ||
322 | * | ||
323 | * For transport mode and equivalent this would be identical to | ||
324 | * output2 (which does not need to be set). While tunnel mode | ||
325 | * and equivalent would set this to a tunnel encapsulation function | ||
326 | * (xfrm4_prepare_output or xfrm6_prepare_output) that would in turn | ||
327 | * call output2. | ||
328 | */ | ||
329 | int (*output)(struct xfrm_state *x, struct sk_buff *skb); | ||
316 | 330 | ||
317 | struct xfrm_state_afinfo *afinfo; | 331 | struct xfrm_state_afinfo *afinfo; |
318 | struct module *owner; | 332 | struct module *owner; |
@@ -454,6 +468,35 @@ struct xfrm_skb_cb { | |||
454 | 468 | ||
455 | #define XFRM_SKB_CB(__skb) ((struct xfrm_skb_cb *)&((__skb)->cb[0])) | 469 | #define XFRM_SKB_CB(__skb) ((struct xfrm_skb_cb *)&((__skb)->cb[0])) |
456 | 470 | ||
471 | /* | ||
472 | * This structure is used by the afinfo prepare_input/prepare_output functions | ||
473 | * to transmit header information to the mode input/output functions. | ||
474 | */ | ||
475 | struct xfrm_mode_skb_cb { | ||
476 | union { | ||
477 | struct inet_skb_parm h4; | ||
478 | struct inet6_skb_parm h6; | ||
479 | } header; | ||
480 | |||
481 | /* Copied from header for IPv4, always set to zero and DF for IPv6. */ | ||
482 | __be16 id; | ||
483 | __be16 frag_off; | ||
484 | |||
485 | /* TOS for IPv4, class for IPv6. */ | ||
486 | u8 tos; | ||
487 | |||
488 | /* TTL for IPv4, hop limitfor IPv6. */ | ||
489 | u8 ttl; | ||
490 | |||
491 | /* Protocol for IPv4, NH for IPv6. */ | ||
492 | u8 protocol; | ||
493 | |||
494 | /* Used by IPv6 only, zero for IPv4. */ | ||
495 | u8 flow_lbl[3]; | ||
496 | }; | ||
497 | |||
498 | #define XFRM_MODE_SKB_CB(__skb) ((struct xfrm_mode_skb_cb *)&((__skb)->cb[0])) | ||
499 | |||
457 | /* Audit Information */ | 500 | /* Audit Information */ |
458 | struct xfrm_audit | 501 | struct xfrm_audit |
459 | { | 502 | { |
@@ -1051,6 +1094,7 @@ extern void xfrm_replay_notify(struct xfrm_state *x, int event); | |||
1051 | extern int xfrm_state_mtu(struct xfrm_state *x, int mtu); | 1094 | extern int xfrm_state_mtu(struct xfrm_state *x, int mtu); |
1052 | extern int xfrm_init_state(struct xfrm_state *x); | 1095 | extern int xfrm_init_state(struct xfrm_state *x); |
1053 | extern int xfrm_output(struct sk_buff *skb); | 1096 | extern int xfrm_output(struct sk_buff *skb); |
1097 | extern int xfrm4_extract_header(struct sk_buff *skb); | ||
1054 | extern int xfrm4_rcv_encap(struct sk_buff *skb, int nexthdr, __be32 spi, | 1098 | extern int xfrm4_rcv_encap(struct sk_buff *skb, int nexthdr, __be32 spi, |
1055 | int encap_type); | 1099 | int encap_type); |
1056 | extern int xfrm4_rcv(struct sk_buff *skb); | 1100 | extern int xfrm4_rcv(struct sk_buff *skb); |
@@ -1060,9 +1104,12 @@ static inline int xfrm4_rcv_spi(struct sk_buff *skb, int nexthdr, __be32 spi) | |||
1060 | return xfrm4_rcv_encap(skb, nexthdr, spi, 0); | 1104 | return xfrm4_rcv_encap(skb, nexthdr, spi, 0); |
1061 | } | 1105 | } |
1062 | 1106 | ||
1107 | extern int xfrm4_extract_output(struct xfrm_state *x, struct sk_buff *skb); | ||
1108 | extern int xfrm4_prepare_output(struct xfrm_state *x, struct sk_buff *skb); | ||
1063 | extern int xfrm4_output(struct sk_buff *skb); | 1109 | extern int xfrm4_output(struct sk_buff *skb); |
1064 | extern int xfrm4_tunnel_register(struct xfrm_tunnel *handler, unsigned short family); | 1110 | extern int xfrm4_tunnel_register(struct xfrm_tunnel *handler, unsigned short family); |
1065 | extern int xfrm4_tunnel_deregister(struct xfrm_tunnel *handler, unsigned short family); | 1111 | extern int xfrm4_tunnel_deregister(struct xfrm_tunnel *handler, unsigned short family); |
1112 | extern int xfrm6_extract_header(struct sk_buff *skb); | ||
1066 | extern int xfrm6_rcv_spi(struct sk_buff *skb, int nexthdr, __be32 spi); | 1113 | extern int xfrm6_rcv_spi(struct sk_buff *skb, int nexthdr, __be32 spi); |
1067 | extern int xfrm6_rcv(struct sk_buff *skb); | 1114 | extern int xfrm6_rcv(struct sk_buff *skb); |
1068 | extern int xfrm6_input_addr(struct sk_buff *skb, xfrm_address_t *daddr, | 1115 | extern int xfrm6_input_addr(struct sk_buff *skb, xfrm_address_t *daddr, |
@@ -1072,6 +1119,8 @@ extern int xfrm6_tunnel_deregister(struct xfrm6_tunnel *handler, unsigned short | |||
1072 | extern __be32 xfrm6_tunnel_alloc_spi(xfrm_address_t *saddr); | 1119 | extern __be32 xfrm6_tunnel_alloc_spi(xfrm_address_t *saddr); |
1073 | extern void xfrm6_tunnel_free_spi(xfrm_address_t *saddr); | 1120 | extern void xfrm6_tunnel_free_spi(xfrm_address_t *saddr); |
1074 | extern __be32 xfrm6_tunnel_spi_lookup(xfrm_address_t *saddr); | 1121 | extern __be32 xfrm6_tunnel_spi_lookup(xfrm_address_t *saddr); |
1122 | extern int xfrm6_extract_output(struct xfrm_state *x, struct sk_buff *skb); | ||
1123 | extern int xfrm6_prepare_output(struct xfrm_state *x, struct sk_buff *skb); | ||
1075 | extern int xfrm6_output(struct sk_buff *skb); | 1124 | extern int xfrm6_output(struct sk_buff *skb); |
1076 | extern int xfrm6_find_1stfragopt(struct xfrm_state *x, struct sk_buff *skb, | 1125 | extern int xfrm6_find_1stfragopt(struct xfrm_state *x, struct sk_buff *skb, |
1077 | u8 **prevhdr); | 1126 | u8 **prevhdr); |