Skip to content

Commit d1df6fd

Browse files
David Lebrundavem330
authored andcommitted
ipv6: sr: define core operations for seg6local lightweight tunnel
This patch implements a new type of lightweight tunnel named seg6local. A seg6local lwt is defined by a type of action and a set of parameters. The action represents the operation to perform on the packets matching the lwt's route, and is not necessarily an encapsulation. The set of parameters are arguments for the processing function. Each action is defined in a struct seg6_action_desc within seg6_action_table[]. This structure contains the action, mandatory attributes, the processing function, and a static headroom size required by the action. The mandatory attributes are encoded as a bitmask field. The static headroom is set to a non-zero value when the processing function always add a constant number of bytes to the skb (e.g. the header size for encapsulations). To facilitate rtnetlink-related operations such as parsing, fill_encap, and cmp_encap, each type of action parameter is associated to three function pointers, in seg6_action_params[]. All actions defined in seg6_local.h are detailed in [1]. [1] https://tools.ietf.org/html/draft-filsfils-spring-srv6-network-programming-01 Signed-off-by: David Lebrun <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent b04c80d commit d1df6fd

File tree

9 files changed

+407
-2
lines changed

9 files changed

+407
-2
lines changed

include/linux/seg6_local.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#ifndef _LINUX_SEG6_LOCAL_H
2+
#define _LINUX_SEG6_LOCAL_H
3+
4+
#include <uapi/linux/seg6_local.h>
5+
6+
#endif

include/net/seg6.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ extern int seg6_init(void);
5656
extern void seg6_exit(void);
5757
extern int seg6_iptunnel_init(void);
5858
extern void seg6_iptunnel_exit(void);
59+
extern int seg6_local_init(void);
60+
extern void seg6_local_exit(void);
5961

6062
extern bool seg6_validate_srh(struct ipv6_sr_hdr *srh, int len);
6163
extern int seg6_do_srh_encap(struct sk_buff *skb, struct ipv6_sr_hdr *osrh);

include/uapi/linux/lwtunnel.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ enum lwtunnel_encap_types {
1111
LWTUNNEL_ENCAP_IP6,
1212
LWTUNNEL_ENCAP_SEG6,
1313
LWTUNNEL_ENCAP_BPF,
14+
LWTUNNEL_ENCAP_SEG6_LOCAL,
1415
__LWTUNNEL_ENCAP_MAX,
1516
};
1617

include/uapi/linux/seg6_local.h

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* SR-IPv6 implementation
3+
*
4+
* Author:
5+
* David Lebrun <[email protected]>
6+
*
7+
*
8+
* This program is free software; you can redistribute it and/or
9+
* modify it under the terms of the GNU General Public License
10+
* as published by the Free Software Foundation; either version
11+
* 2 of the License, or (at your option) any later version.
12+
*/
13+
14+
#ifndef _UAPI_LINUX_SEG6_LOCAL_H
15+
#define _UAPI_LINUX_SEG6_LOCAL_H
16+
17+
#include <linux/seg6.h>
18+
19+
enum {
20+
SEG6_LOCAL_UNSPEC,
21+
SEG6_LOCAL_ACTION,
22+
SEG6_LOCAL_SRH,
23+
SEG6_LOCAL_TABLE,
24+
SEG6_LOCAL_NH4,
25+
SEG6_LOCAL_NH6,
26+
SEG6_LOCAL_IIF,
27+
SEG6_LOCAL_OIF,
28+
__SEG6_LOCAL_MAX,
29+
};
30+
#define SEG6_LOCAL_MAX (__SEG6_LOCAL_MAX - 1)
31+
32+
enum {
33+
SEG6_LOCAL_ACTION_UNSPEC = 0,
34+
/* node segment */
35+
SEG6_LOCAL_ACTION_END = 1,
36+
/* adjacency segment (IPv6 cross-connect) */
37+
SEG6_LOCAL_ACTION_END_X = 2,
38+
/* lookup of next seg NH in table */
39+
SEG6_LOCAL_ACTION_END_T = 3,
40+
/* decap and L2 cross-connect */
41+
SEG6_LOCAL_ACTION_END_DX2 = 4,
42+
/* decap and IPv6 cross-connect */
43+
SEG6_LOCAL_ACTION_END_DX6 = 5,
44+
/* decap and IPv4 cross-connect */
45+
SEG6_LOCAL_ACTION_END_DX4 = 6,
46+
/* decap and lookup of DA in v6 table */
47+
SEG6_LOCAL_ACTION_END_DT6 = 7,
48+
/* decap and lookup of DA in v4 table */
49+
SEG6_LOCAL_ACTION_END_DT4 = 8,
50+
/* binding segment with insertion */
51+
SEG6_LOCAL_ACTION_END_B6 = 9,
52+
/* binding segment with encapsulation */
53+
SEG6_LOCAL_ACTION_END_B6_ENCAP = 10,
54+
/* binding segment with MPLS encap */
55+
SEG6_LOCAL_ACTION_END_BM = 11,
56+
/* lookup last seg in table */
57+
SEG6_LOCAL_ACTION_END_S = 12,
58+
/* forward to SR-unaware VNF with static proxy */
59+
SEG6_LOCAL_ACTION_END_AS = 13,
60+
/* forward to SR-unaware VNF with masquerading */
61+
SEG6_LOCAL_ACTION_END_AM = 14,
62+
63+
__SEG6_LOCAL_ACTION_MAX,
64+
};
65+
66+
#define SEG6_LOCAL_ACTION_MAX (__SEG6_LOCAL_ACTION_MAX - 1)
67+
68+
#endif

net/core/lwtunnel.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ static const char *lwtunnel_encap_str(enum lwtunnel_encap_types encap_type)
4444
return "SEG6";
4545
case LWTUNNEL_ENCAP_BPF:
4646
return "BPF";
47+
case LWTUNNEL_ENCAP_SEG6_LOCAL:
48+
return "SEG6LOCAL";
4749
case LWTUNNEL_ENCAP_IP6:
4850
case LWTUNNEL_ENCAP_IP:
4951
case LWTUNNEL_ENCAP_NONE:

net/ipv6/Kconfig

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,8 @@ config IPV6_SEG6_LWTUNNEL
311311
---help---
312312
Support for encapsulation of packets within an outer IPv6
313313
header and a Segment Routing Header using the lightweight
314-
tunnels mechanism.
314+
tunnels mechanism. Also enable support for advanced local
315+
processing of SRv6 packets based on their active segment.
315316

316317
If unsure, say N.
317318

net/ipv6/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ ipv6-$(CONFIG_IPV6_MULTIPLE_TABLES) += fib6_rules.o
2323
ipv6-$(CONFIG_PROC_FS) += proc.o
2424
ipv6-$(CONFIG_SYN_COOKIES) += syncookies.o
2525
ipv6-$(CONFIG_NETLABEL) += calipso.o
26-
ipv6-$(CONFIG_IPV6_SEG6_LWTUNNEL) += seg6_iptunnel.o
26+
ipv6-$(CONFIG_IPV6_SEG6_LWTUNNEL) += seg6_iptunnel.o seg6_local.o
2727
ipv6-$(CONFIG_IPV6_SEG6_HMAC) += seg6_hmac.o
2828

2929
ipv6-objs += $(ipv6-y)

net/ipv6/seg6.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,10 @@ int __init seg6_init(void)
456456
err = seg6_iptunnel_init();
457457
if (err)
458458
goto out_unregister_pernet;
459+
460+
err = seg6_local_init();
461+
if (err)
462+
goto out_unregister_pernet;
459463
#endif
460464

461465
#ifdef CONFIG_IPV6_SEG6_HMAC
@@ -471,6 +475,7 @@ int __init seg6_init(void)
471475
#ifdef CONFIG_IPV6_SEG6_HMAC
472476
out_unregister_iptun:
473477
#ifdef CONFIG_IPV6_SEG6_LWTUNNEL
478+
seg6_local_exit();
474479
seg6_iptunnel_exit();
475480
#endif
476481
#endif

0 commit comments

Comments
 (0)