netfilter: add segment routing header 'srh' match
Subsystems (2)
PATCH v2 1/1 netfilter: add segment routing header 'srh' match
It allows matching packets based on Segment Routing Header (SRH) information.
The implementation considers revision 7 of the SRH draft.
https://tools.ietf.org/html/draft-ietf-6man-segment-routing-header-07
Currently supported match options include:
(1) Next Header
(2) Hdr Ext Len
(3) Segments Left
(4) Last Entry
(5) Tag value of SRH
--- include/uapi/linux/netfilter_ipv6/ip6t_srh.h | 57 ++++++++++ net/ipv6/netfilter/Kconfig | 9 ++ net/ipv6/netfilter/Makefile | 1 + net/ipv6/netfilter/ip6t_srh.c | 161 +++++++++++++++++++++++++++ 4 files changed, 228 insertions(+) create mode 100644 include/uapi/linux/netfilter_ipv6/ip6t_srh.h create mode 100644 net/ipv6/netfilter/ip6t_srh.c
include/uapi/linux/netfilter_ipv6/ip6t_srh.h new file +57 -0
@@ -0,0 +1,57 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +#ifndef _IP6T_SRH_H +#define _IP6T_SRH_H + +#include <linux/types.h> +#include <linux/netfilter.h> + +/* Values for "mt_flags" field in struct ip6t_srh */ +#define IP6T_SRH_NEXTHDR 0x0001 +#define IP6T_SRH_LEN_EQ 0x0002 +#define IP6T_SRH_LEN_GT 0x0004 +#define IP6T_SRH_LEN_LT 0x0008 +#define IP6T_SRH_SEGS_EQ 0x0010 +#define IP6T_SRH_SEGS_GT 0x0020 +#define IP6T_SRH_SEGS_LT 0x0040 +#define IP6T_SRH_LAST_EQ 0x0080 +#define IP6T_SRH_LAST_GT 0x0100 +#define IP6T_SRH_LAST_LT 0x0200 +#define IP6T_SRH_TAG 0x0400 +#define IP6T_SRH_MASK 0x07FF + +/* Values for "mt_invflags" field in struct ip6t_srh */ +#define IP6T_SRH_INV_NEXTHDR 0x0001 +#define IP6T_SRH_INV_LEN_EQ 0x0002 +#define IP6T_SRH_INV_LEN_GT 0x0004 +#define IP6T_SRH_INV_LEN_LT 0x0008 +#define IP6T_SRH_INV_SEGS_EQ 0x0010 +#define IP6T_SRH_INV_SEGS_GT 0x0020 +#define IP6T_SRH_INV_SEGS_LT 0x0040 +#define IP6T_SRH_INV_LAST_EQ 0x0080 +#define IP6T_SRH_INV_LAST_GT 0x0100 +#define IP6T_SRH_INV_LAST_LT 0x0200 +#define IP6T_SRH_INV_TAG 0x0400 +#define IP6T_SRH_INV_MASK 0x07FF + +/** +* struct ip6t_srh - SRH match options +* @ next_hdr: Next header field of SRH +* @ hdr_len: Extension header length field of SRH +* @ segs_left: Segments left field of SRH +* @ last_entry: Last entry field of SRH +* @ tag: Tag field of SRH +* @ mt_flags: match options +* @ mt_invflags: Invert the sense of match options +*/ + +struct ip6t_srh { +__u8 next_hdr; +__u8 hdr_len; +__u8 segs_left; +__u8 last_entry; +__u16 tag; +__u16 mt_flags; +__u16 mt_invflags; +}; + +#endif /*_IP6T_SRH_H*/
net/ipv6/netfilter/Kconfig +9 -0
@@ -232,6 +232,15 @@ config IP6_NF_MATCH_RT To compile it as a module, choose M here. If unsure, say N. +config IP6_NF_MATCH_SRH + tristate '"srh" Segment Routing header match support' + depends on NETFILTER_ADVANCED + help + srh matching allows you to match packets based on the segment + routing header of the packet. + + To compile it as a module, choose M here. If unsure, say N. + # The targets config IP6_NF_TARGET_HL tristate '"HL" hoplimit target support'
net/ipv6/netfilter/Makefile +1 -0
@@ -54,6 +54,7 @@ obj-$(CONFIG_IP6_NF_MATCH_MH) += ip6t_mh.o obj-$(CONFIG_IP6_NF_MATCH_OPTS) += ip6t_hbh.o obj-$(CONFIG_IP6_NF_MATCH_RPFILTER) += ip6t_rpfilter.o obj-$(CONFIG_IP6_NF_MATCH_RT) += ip6t_rt.o +obj-$(CONFIG_IP6_NF_MATCH_SRH) += ip6t_srh.o # targets obj-$(CONFIG_IP6_NF_TARGET_MASQUERADE) += ip6t_MASQUERADE.o
net/ipv6/netfilter/ip6t_srh.c new file +161 -0
161 lines not on this page · raw message
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerQuoted 11 lines · Ahmed Abdelsalam
It allows matching packets based on Segment Routing Header (SRH) information.
The implementation considers revision 7 of the SRH draft.
https://tools.ietf.org/html/draft-ietf-6man-segment-routing-header-07Currently supported match options include:
(1) Next Header
(2) Hdr Ext Len
(3) Segments Left
(4) Last Entry
(5) Tag value of SRH
net/ipv6/netfilter/ip6t_srh.c: In function ‘srh_mt6’:net/ipv6/netfilter/ip6t_srh.c:115:10: error: ‘struct ipv6_sr_hdr’ has no member named ‘tag’
!(srh->tag == srhinfo->tag)))
^
net/ipv6/netfilter/ip6t_srh.c:26:4: note: in definition of macro
‘NF_SRH_INVF’
((boolean) ^ !!((ptr)->mt_invflags & (flag)))
^Something breaks compilation here.
A message that is not in the archive (sent off-list or not yet received): [email protected]
Pablo Neira Ayuso
maintainerQuoted 26 lines · Ahmed AbdelSalam
Quoted 26 lines · Pablo Neira Ayuso
Quoted 11 lines · Ahmed Abdelsalam
It allows matching packets based on Segment Routing Header (SRH) information.
The implementation considers revision 7 of the SRH draft.
https://tools.ietf.org/html/draft-ietf-6man-segment-routing-header-07Currently supported match options include:
(1) Next Header
(2) Hdr Ext Len
(3) Segments Left
(4) Last Entry
(5) Tag value of SRH
net/ipv6/netfilter/ip6t_srh.c: In function ‘srh_mt6’:net/ipv6/netfilter/ip6t_srh.c:115:10: error: ‘struct ipv6_sr_hdr’ has no member named ‘tag’!(srh->tag == srhinfo->tag))) ^
net/ipv6/netfilter/ip6t_srh.c:26:4: note: in definition of macro ‘NF_SRH_INVF’
((boolean) ^ !!((ptr)->mt_invflags & (flag)))
^
Quoted 7 lines
Quoted 1 line
Something breaks compilation here.
This patch is based on David Miller net-next tree.
The reason for the compilation error is that you don’t have in your tree the following patch
ipv6: sr: update the structipv6_sr_hdr(https://patchwork.ozlabs.org/patch/838198/ <https://patchwork.ozlabs.org/patch/838198/>).
In this patch the “tag” field was introduced to replace the reserved bits of SRH
OK. I'll included this in the next batch, once nf-next gets in sync with net-next.
Thanks for explaining.
Pablo Neira Ayuso
maintainerQuoted 11 lines · Ahmed Abdelsalam
It allows matching packets based on Segment Routing Header (SRH) information.
The implementation considers revision 7 of the SRH draft.
https://tools.ietf.org/html/draft-ietf-6man-segment-routing-header-07Currently supported match options include:
(1) Next Header
(2) Hdr Ext Len
(3) Segments Left
(4) Last Entry
(5) Tag value of SRH
Now applied to nf-next, thanks for your patience.