Skip to content

Commit 995dca4

Browse files
committed
Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/klassert/ipsec-next
Steffen Klassert says: ==================== One patch to rename a newly introduced struct. The rest is the rework of the IPsec virtual tunnel interface for ipv6 to support inter address family tunneling and namespace crossing. 1) Rename the newly introduced struct xfrm_filter to avoid a conflict with iproute2. From Nicolas Dichtel. 2) Introduce xfrm_input_afinfo to access the address family dependent tunnel callback functions properly. 3) Add and use a IPsec protocol multiplexer for ipv6. 4) Remove dst_entry caching. vti can lookup multiple different dst entries, dependent of the configured xfrm states. Therefore it does not make to cache a dst_entry. 5) Remove caching of flow informations. vti6 does not use the the tunnel endpoint addresses to do route and xfrm lookups. 6) Update the vti6 to use its own receive hook. 7) Remove the now unused xfrm_tunnel_notifier. This was used from vti and is replaced by the IPsec protocol multiplexer hooks. 8) Support inter address family tunneling for vti6. 9) Check if the tunnel endpoints of the xfrm state and the vti interface are matching and return an error otherwise. 10) Enable namespace crossing for vti devices. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
2 parents d70e941 + 61220ab commit 995dca4

16 files changed

Lines changed: 668 additions & 211 deletions

File tree

‎include/net/xfrm.h‎

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ struct xfrm_state_walk {
121121
u8 dying;
122122
u8 proto;
123123
u32 seq;
124-
struct xfrm_filter *filter;
124+
struct xfrm_address_filter *filter;
125125
};
126126

127127
/* Full description of state of transformer. */
@@ -349,6 +349,16 @@ int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
349349
struct xfrm_state_afinfo *xfrm_state_get_afinfo(unsigned int family);
350350
void xfrm_state_put_afinfo(struct xfrm_state_afinfo *afinfo);
351351

352+
struct xfrm_input_afinfo {
353+
unsigned int family;
354+
struct module *owner;
355+
int (*callback)(struct sk_buff *skb, u8 protocol,
356+
int err);
357+
};
358+
359+
int xfrm_input_register_afinfo(struct xfrm_input_afinfo *afinfo);
360+
int xfrm_input_unregister_afinfo(struct xfrm_input_afinfo *afinfo);
361+
352362
void xfrm_state_delete_tunnel(struct xfrm_state *x);
353363

354364
struct xfrm_type {
@@ -1364,18 +1374,22 @@ struct xfrm4_protocol {
13641374
int priority;
13651375
};
13661376

1367-
/* XFRM tunnel handlers. */
1368-
struct xfrm_tunnel {
1377+
struct xfrm6_protocol {
13691378
int (*handler)(struct sk_buff *skb);
1370-
int (*err_handler)(struct sk_buff *skb, u32 info);
1379+
int (*cb_handler)(struct sk_buff *skb, int err);
1380+
int (*err_handler)(struct sk_buff *skb, struct inet6_skb_parm *opt,
1381+
u8 type, u8 code, int offset, __be32 info);
13711382

1372-
struct xfrm_tunnel __rcu *next;
1383+
struct xfrm6_protocol __rcu *next;
13731384
int priority;
13741385
};
13751386

1376-
struct xfrm_tunnel_notifier {
1387+
/* XFRM tunnel handlers. */
1388+
struct xfrm_tunnel {
13771389
int (*handler)(struct sk_buff *skb);
1378-
struct xfrm_tunnel_notifier __rcu *next;
1390+
int (*err_handler)(struct sk_buff *skb, u32 info);
1391+
1392+
struct xfrm_tunnel __rcu *next;
13791393
int priority;
13801394
};
13811395

@@ -1392,11 +1406,14 @@ void xfrm4_init(void);
13921406
int xfrm_state_init(struct net *net);
13931407
void xfrm_state_fini(struct net *net);
13941408
void xfrm4_state_init(void);
1409+
void xfrm4_protocol_init(void);
13951410
#ifdef CONFIG_XFRM
13961411
int xfrm6_init(void);
13971412
void xfrm6_fini(void);
13981413
int xfrm6_state_init(void);
13991414
void xfrm6_state_fini(void);
1415+
int xfrm6_protocol_init(void);
1416+
void xfrm6_protocol_fini(void);
14001417
#else
14011418
static inline int xfrm6_init(void)
14021419
{
@@ -1423,7 +1440,7 @@ static inline void xfrm_sysctl_fini(struct net *net)
14231440
#endif
14241441

14251442
void xfrm_state_walk_init(struct xfrm_state_walk *walk, u8 proto,
1426-
struct xfrm_filter *filter);
1443+
struct xfrm_address_filter *filter);
14271444
int xfrm_state_walk(struct net *net, struct xfrm_state_walk *walk,
14281445
int (*func)(struct xfrm_state *, int, void*), void *);
14291446
void xfrm_state_walk_done(struct xfrm_state_walk *walk, struct net *net);
@@ -1531,8 +1548,6 @@ int xfrm4_protocol_deregister(struct xfrm4_protocol *handler, unsigned char prot
15311548
int xfrm4_tunnel_register(struct xfrm_tunnel *handler, unsigned short family);
15321549
int xfrm4_tunnel_deregister(struct xfrm_tunnel *handler, unsigned short family);
15331550
void xfrm4_local_error(struct sk_buff *skb, u32 mtu);
1534-
int xfrm6_mode_tunnel_input_register(struct xfrm_tunnel_notifier *handler);
1535-
int xfrm6_mode_tunnel_input_deregister(struct xfrm_tunnel_notifier *handler);
15361551
int xfrm6_extract_header(struct sk_buff *skb);
15371552
int xfrm6_extract_input(struct xfrm_state *x, struct sk_buff *skb);
15381553
int xfrm6_rcv_spi(struct sk_buff *skb, int nexthdr, __be32 spi);
@@ -1541,6 +1556,9 @@ int xfrm6_rcv(struct sk_buff *skb);
15411556
int xfrm6_input_addr(struct sk_buff *skb, xfrm_address_t *daddr,
15421557
xfrm_address_t *saddr, u8 proto);
15431558
void xfrm6_local_error(struct sk_buff *skb, u32 mtu);
1559+
int xfrm6_rcv_cb(struct sk_buff *skb, u8 protocol, int err);
1560+
int xfrm6_protocol_register(struct xfrm6_protocol *handler, unsigned char protocol);
1561+
int xfrm6_protocol_deregister(struct xfrm6_protocol *handler, unsigned char protocol);
15441562
int xfrm6_tunnel_register(struct xfrm6_tunnel *handler, unsigned short family);
15451563
int xfrm6_tunnel_deregister(struct xfrm6_tunnel *handler, unsigned short family);
15461564
__be32 xfrm6_tunnel_alloc_spi(struct net *net, xfrm_address_t *saddr);
@@ -1784,18 +1802,6 @@ static inline int xfrm_mark_put(struct sk_buff *skb, const struct xfrm_mark *m)
17841802
return ret;
17851803
}
17861804

1787-
static inline int xfrm_rcv_cb(struct sk_buff *skb, unsigned int family,
1788-
u8 protocol, int err)
1789-
{
1790-
switch(family) {
1791-
#ifdef CONFIG_INET
1792-
case AF_INET:
1793-
return xfrm4_rcv_cb(skb, protocol, err);
1794-
#endif
1795-
}
1796-
return 0;
1797-
}
1798-
17991805
static inline int xfrm_tunnel_check(struct sk_buff *skb, struct xfrm_state *x,
18001806
unsigned int family)
18011807
{

‎include/uapi/linux/xfrm.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ enum xfrm_attr_type_t {
299299
XFRMA_REPLAY_ESN_VAL, /* struct xfrm_replay_esn */
300300
XFRMA_SA_EXTRA_FLAGS, /* __u32 */
301301
XFRMA_PROTO, /* __u8 */
302-
XFRMA_FILTER, /* struct xfrm_filter */
302+
XFRMA_ADDRESS_FILTER, /* struct xfrm_address_filter */
303303
__XFRMA_MAX
304304

305305
#define XFRMA_MAX (__XFRMA_MAX - 1)
@@ -476,7 +476,7 @@ struct xfrm_user_mapping {
476476
__be16 new_sport;
477477
};
478478

479-
struct xfrm_filter {
479+
struct xfrm_address_filter {
480480
xfrm_address_t saddr;
481481
xfrm_address_t daddr;
482482
__u16 family;

‎net/ipv4/xfrm4_policy.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,7 @@ void __init xfrm4_init(void)
325325

326326
xfrm4_state_init();
327327
xfrm4_policy_init();
328+
xfrm4_protocol_init();
328329
#ifdef CONFIG_SYSCTL
329330
register_pernet_subsys(&xfrm4_net_ops);
330331
#endif

‎net/ipv4/xfrm4_protocol.c‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,12 @@ static const struct net_protocol ipcomp4_protocol = {
179179
.netns_ok = 1,
180180
};
181181

182+
static struct xfrm_input_afinfo xfrm4_input_afinfo = {
183+
.family = AF_INET,
184+
.owner = THIS_MODULE,
185+
.callback = xfrm4_rcv_cb,
186+
};
187+
182188
static inline const struct net_protocol *netproto(unsigned char protocol)
183189
{
184190
switch (protocol) {
@@ -199,7 +205,6 @@ int xfrm4_protocol_register(struct xfrm4_protocol *handler,
199205
struct xfrm4_protocol __rcu **pprev;
200206
struct xfrm4_protocol *t;
201207
bool add_netproto = false;
202-
203208
int ret = -EEXIST;
204209
int priority = handler->priority;
205210

@@ -273,3 +278,9 @@ int xfrm4_protocol_deregister(struct xfrm4_protocol *handler,
273278
return ret;
274279
}
275280
EXPORT_SYMBOL(xfrm4_protocol_deregister);
281+
282+
void __init xfrm4_protocol_init(void)
283+
{
284+
xfrm_input_register_afinfo(&xfrm4_input_afinfo);
285+
}
286+
EXPORT_SYMBOL(xfrm4_protocol_init);

‎net/ipv6/Makefile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ ipv6-$(CONFIG_SYSCTL) = sysctl_net_ipv6.o
1616
ipv6-$(CONFIG_IPV6_MROUTE) += ip6mr.o
1717

1818
ipv6-$(CONFIG_XFRM) += xfrm6_policy.o xfrm6_state.o xfrm6_input.o \
19-
xfrm6_output.o
19+
xfrm6_output.o xfrm6_protocol.o
2020
ipv6-$(CONFIG_NETFILTER) += netfilter.o
2121
ipv6-$(CONFIG_IPV6_MULTIPLE_TABLES) += fib6_rules.o
2222
ipv6-$(CONFIG_PROC_FS) += proc.o

‎net/ipv6/ah6.c‎

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -643,8 +643,8 @@ static int ah6_input(struct xfrm_state *x, struct sk_buff *skb)
643643
return err;
644644
}
645645

646-
static void ah6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
647-
u8 type, u8 code, int offset, __be32 info)
646+
static int ah6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
647+
u8 type, u8 code, int offset, __be32 info)
648648
{
649649
struct net *net = dev_net(skb->dev);
650650
struct ipv6hdr *iph = (struct ipv6hdr*)skb->data;
@@ -653,17 +653,19 @@ static void ah6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
653653

654654
if (type != ICMPV6_PKT_TOOBIG &&
655655
type != NDISC_REDIRECT)
656-
return;
656+
return 0;
657657

658658
x = xfrm_state_lookup(net, skb->mark, (xfrm_address_t *)&iph->daddr, ah->spi, IPPROTO_AH, AF_INET6);
659659
if (!x)
660-
return;
660+
return 0;
661661

662662
if (type == NDISC_REDIRECT)
663663
ip6_redirect(skb, net, skb->dev->ifindex, 0);
664664
else
665665
ip6_update_pmtu(skb, net, info, 0, 0);
666666
xfrm_state_put(x);
667+
668+
return 0;
667669
}
668670

669671
static int ah6_init_state(struct xfrm_state *x)
@@ -748,6 +750,11 @@ static void ah6_destroy(struct xfrm_state *x)
748750
kfree(ahp);
749751
}
750752

753+
static int ah6_rcv_cb(struct sk_buff *skb, int err)
754+
{
755+
return 0;
756+
}
757+
751758
static const struct xfrm_type ah6_type =
752759
{
753760
.description = "AH6",
@@ -761,10 +768,11 @@ static const struct xfrm_type ah6_type =
761768
.hdr_offset = xfrm6_find_1stfragopt,
762769
};
763770

764-
static const struct inet6_protocol ah6_protocol = {
771+
static struct xfrm6_protocol ah6_protocol = {
765772
.handler = xfrm6_rcv,
773+
.cb_handler = ah6_rcv_cb,
766774
.err_handler = ah6_err,
767-
.flags = INET6_PROTO_NOPOLICY,
775+
.priority = 0,
768776
};
769777

770778
static int __init ah6_init(void)
@@ -774,7 +782,7 @@ static int __init ah6_init(void)
774782
return -EAGAIN;
775783
}
776784

777-
if (inet6_add_protocol(&ah6_protocol, IPPROTO_AH) < 0) {
785+
if (xfrm6_protocol_register(&ah6_protocol, IPPROTO_AH) < 0) {
778786
pr_info("%s: can't add protocol\n", __func__);
779787
xfrm_unregister_type(&ah6_type, AF_INET6);
780788
return -EAGAIN;
@@ -785,7 +793,7 @@ static int __init ah6_init(void)
785793

786794
static void __exit ah6_fini(void)
787795
{
788-
if (inet6_del_protocol(&ah6_protocol, IPPROTO_AH) < 0)
796+
if (xfrm6_protocol_deregister(&ah6_protocol, IPPROTO_AH) < 0)
789797
pr_info("%s: can't remove protocol\n", __func__);
790798

791799
if (xfrm_unregister_type(&ah6_type, AF_INET6) < 0)

‎net/ipv6/esp6.c‎

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -421,8 +421,8 @@ static u32 esp6_get_mtu(struct xfrm_state *x, int mtu)
421421
net_adj) & ~(blksize - 1)) + net_adj - 2;
422422
}
423423

424-
static void esp6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
425-
u8 type, u8 code, int offset, __be32 info)
424+
static int esp6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
425+
u8 type, u8 code, int offset, __be32 info)
426426
{
427427
struct net *net = dev_net(skb->dev);
428428
const struct ipv6hdr *iph = (const struct ipv6hdr *)skb->data;
@@ -431,18 +431,20 @@ static void esp6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
431431

432432
if (type != ICMPV6_PKT_TOOBIG &&
433433
type != NDISC_REDIRECT)
434-
return;
434+
return 0;
435435

436436
x = xfrm_state_lookup(net, skb->mark, (const xfrm_address_t *)&iph->daddr,
437437
esph->spi, IPPROTO_ESP, AF_INET6);
438438
if (!x)
439-
return;
439+
return 0;
440440

441441
if (type == NDISC_REDIRECT)
442442
ip6_redirect(skb, net, skb->dev->ifindex, 0);
443443
else
444444
ip6_update_pmtu(skb, net, info, 0, 0);
445445
xfrm_state_put(x);
446+
447+
return 0;
446448
}
447449

448450
static void esp6_destroy(struct xfrm_state *x)
@@ -614,6 +616,11 @@ static int esp6_init_state(struct xfrm_state *x)
614616
return err;
615617
}
616618

619+
static int esp6_rcv_cb(struct sk_buff *skb, int err)
620+
{
621+
return 0;
622+
}
623+
617624
static const struct xfrm_type esp6_type =
618625
{
619626
.description = "ESP6",
@@ -628,10 +635,11 @@ static const struct xfrm_type esp6_type =
628635
.hdr_offset = xfrm6_find_1stfragopt,
629636
};
630637

631-
static const struct inet6_protocol esp6_protocol = {
632-
.handler = xfrm6_rcv,
638+
static struct xfrm6_protocol esp6_protocol = {
639+
.handler = xfrm6_rcv,
640+
.cb_handler = esp6_rcv_cb,
633641
.err_handler = esp6_err,
634-
.flags = INET6_PROTO_NOPOLICY,
642+
.priority = 0,
635643
};
636644

637645
static int __init esp6_init(void)
@@ -640,7 +648,7 @@ static int __init esp6_init(void)
640648
pr_info("%s: can't add xfrm type\n", __func__);
641649
return -EAGAIN;
642650
}
643-
if (inet6_add_protocol(&esp6_protocol, IPPROTO_ESP) < 0) {
651+
if (xfrm6_protocol_register(&esp6_protocol, IPPROTO_ESP) < 0) {
644652
pr_info("%s: can't add protocol\n", __func__);
645653
xfrm_unregister_type(&esp6_type, AF_INET6);
646654
return -EAGAIN;
@@ -651,7 +659,7 @@ static int __init esp6_init(void)
651659

652660
static void __exit esp6_fini(void)
653661
{
654-
if (inet6_del_protocol(&esp6_protocol, IPPROTO_ESP) < 0)
662+
if (xfrm6_protocol_deregister(&esp6_protocol, IPPROTO_ESP) < 0)
655663
pr_info("%s: can't remove protocol\n", __func__);
656664
if (xfrm_unregister_type(&esp6_type, AF_INET6) < 0)
657665
pr_info("%s: can't remove xfrm type\n", __func__);

0 commit comments

Comments
 (0)