aboutsummaryrefslogtreecommitdiffstats
path: root/include/net
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2007-11-14 00:40:52 -0500
committerDavid S. Miller <davem@davemloft.net>2008-01-28 17:53:45 -0500
commit36cf9acf93e8561d9faec24849e57688a81eb9c5 (patch)
treefd4fab84132f1784a23441e03c4a0b9aea6cc43a /include/net
parent29bb43b4ec4e625b0659186fc8a7c8f8b7c81982 (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/net')
-rw-r--r--include/net/xfrm.h51
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
258struct xfrm_state_afinfo { 258struct 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
272extern int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo); 275extern 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 */
475struct 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 */
458struct xfrm_audit 501struct xfrm_audit
459{ 502{
@@ -1051,6 +1094,7 @@ extern void xfrm_replay_notify(struct xfrm_state *x, int event);
1051extern int xfrm_state_mtu(struct xfrm_state *x, int mtu); 1094extern int xfrm_state_mtu(struct xfrm_state *x, int mtu);
1052extern int xfrm_init_state(struct xfrm_state *x); 1095extern int xfrm_init_state(struct xfrm_state *x);
1053extern int xfrm_output(struct sk_buff *skb); 1096extern int xfrm_output(struct sk_buff *skb);
1097extern int xfrm4_extract_header(struct sk_buff *skb);
1054extern int xfrm4_rcv_encap(struct sk_buff *skb, int nexthdr, __be32 spi, 1098extern int xfrm4_rcv_encap(struct sk_buff *skb, int nexthdr, __be32 spi,
1055 int encap_type); 1099 int encap_type);
1056extern int xfrm4_rcv(struct sk_buff *skb); 1100extern 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
1107extern int xfrm4_extract_output(struct xfrm_state *x, struct sk_buff *skb);
1108extern int xfrm4_prepare_output(struct xfrm_state *x, struct sk_buff *skb);
1063extern int xfrm4_output(struct sk_buff *skb); 1109extern int xfrm4_output(struct sk_buff *skb);
1064extern int xfrm4_tunnel_register(struct xfrm_tunnel *handler, unsigned short family); 1110extern int xfrm4_tunnel_register(struct xfrm_tunnel *handler, unsigned short family);
1065extern int xfrm4_tunnel_deregister(struct xfrm_tunnel *handler, unsigned short family); 1111extern int xfrm4_tunnel_deregister(struct xfrm_tunnel *handler, unsigned short family);
1112extern int xfrm6_extract_header(struct sk_buff *skb);
1066extern int xfrm6_rcv_spi(struct sk_buff *skb, int nexthdr, __be32 spi); 1113extern int xfrm6_rcv_spi(struct sk_buff *skb, int nexthdr, __be32 spi);
1067extern int xfrm6_rcv(struct sk_buff *skb); 1114extern int xfrm6_rcv(struct sk_buff *skb);
1068extern int xfrm6_input_addr(struct sk_buff *skb, xfrm_address_t *daddr, 1115extern 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
1072extern __be32 xfrm6_tunnel_alloc_spi(xfrm_address_t *saddr); 1119extern __be32 xfrm6_tunnel_alloc_spi(xfrm_address_t *saddr);
1073extern void xfrm6_tunnel_free_spi(xfrm_address_t *saddr); 1120extern void xfrm6_tunnel_free_spi(xfrm_address_t *saddr);
1074extern __be32 xfrm6_tunnel_spi_lookup(xfrm_address_t *saddr); 1121extern __be32 xfrm6_tunnel_spi_lookup(xfrm_address_t *saddr);
1122extern int xfrm6_extract_output(struct xfrm_state *x, struct sk_buff *skb);
1123extern int xfrm6_prepare_output(struct xfrm_state *x, struct sk_buff *skb);
1075extern int xfrm6_output(struct sk_buff *skb); 1124extern int xfrm6_output(struct sk_buff *skb);
1076extern int xfrm6_find_1stfragopt(struct xfrm_state *x, struct sk_buff *skb, 1125extern int xfrm6_find_1stfragopt(struct xfrm_state *x, struct sk_buff *skb,
1077 u8 **prevhdr); 1126 u8 **prevhdr);