Re: [nft] nftables: Adding support for segment routing header 'srh'

2018-03-11 Thread Pablo Neira Ayuso
On Tue, Feb 27, 2018 at 11:04:14AM +0100, Ahmed Abdelsalam wrote:
> Segment Routing Header "SRH" is new type of IPv6 Routing extension
> header (type 4).
> 
> SRH contains a list of segments (each is represented as an IPv6 address)
> to be visited by packets during the journey from source to destination.
> 
> The SRH specification are defined in the below IETF SRH draft.
> https://tools.ietf.org/html/draft-ietf-6man-segment-routing-header-07

Also applied, thanks.
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[nft] nftables: Adding support for segment routing header 'srh'

2018-02-28 Thread Ahmed Abdelsalam
Segment Routing Header "SRH" is new type of IPv6 Routing extension
header (type 4).

SRH contains a list of segments (each is represented as an IPv6 address)
to be visited by packets during the journey from source to destination.

The SRH specification are defined in the below IETF SRH draft.
https://tools.ietf.org/html/draft-ietf-6man-segment-routing-header-07

Signed-off-by: Ahmed Abdelsalam 
---
This patch should be applied after those two patches
http://patchwork.ozlabs.org/patch/878674/
http://patchwork.ozlabs.org/patch/878675/

 include/exthdr.h   |  9 +
 include/headers.h  | 12 
 src/exthdr.c   | 23 +++
 src/parser_bison.y | 26 +++---
 src/scanner.l  |  4 
 5 files changed, 71 insertions(+), 3 deletions(-)

diff --git a/include/exthdr.h b/include/exthdr.h
index 06bf628..32f99c9 100644
--- a/include/exthdr.h
+++ b/include/exthdr.h
@@ -57,6 +57,14 @@ enum rt2_hdr_fields {
RT2HDR_ADDR,
 };
 
+enum rt4_hdr_fields {
+   RT4HDR_INVALID,
+   RT4HDR_LASTENT,
+   RT4HDR_FLAGS,
+   RT4HDR_TAG,
+   RT4HDR_SID_1,
+};
+
 enum frag_hdr_fields {
FRAGHDR_INVALID,
FRAGHDR_NEXTHDR,
@@ -87,6 +95,7 @@ extern const struct exthdr_desc exthdr_hbh;
 extern const struct exthdr_desc exthdr_rt;
 extern const struct exthdr_desc exthdr_rt0;
 extern const struct exthdr_desc exthdr_rt2;
+extern const struct exthdr_desc exthdr_rt4;
 extern const struct exthdr_desc exthdr_frag;
 extern const struct exthdr_desc exthdr_dst;
 extern const struct exthdr_desc exthdr_mh;
diff --git a/include/headers.h b/include/headers.h
index 469d674..3d564de 100644
--- a/include/headers.h
+++ b/include/headers.h
@@ -112,6 +112,18 @@ struct ip6_mh {
uint8_t data[0];
 };
 
+/* Type 4 Routing header - well known as srh */
+struct ip6_rt4 {
+   uint8_t ip6r4_nxt;  /* next header  
*/
+   uint8_t ip6r4_len;  /* length in units of 8 octets  
*/
+   uint8_t ip6r4_type; /* always zero  
*/
+   uint8_t ip6r4_segleft;  /* segments left
*/
+   uint8_t ip6r4_last_entry;   /* last entry   
*/
+   uint8_t ip6r4_flags;/* flags
*/
+   uint16_tip6r4_tag;  /* tag  
*/
+   struct in6_addr ip6r4_segments[0];  /* SID list 
*/
+};
+
 /* RFC 3775 */
 #define IP6_MH_TYPE_BRR0   /* Binding Refresh Request  
*/
 #define IP6_MH_TYPE_HOTI   1   /* HOTI Message */
diff --git a/src/exthdr.c b/src/exthdr.c
index 3757f33..cbe0da8 100644
--- a/src/exthdr.c
+++ b/src/exthdr.c
@@ -101,6 +101,9 @@ struct expr *exthdr_expr_alloc(const struct location *loc,
case 2:
expr->exthdr.op = NFT_EXTHDR_OP_RT2;
break;
+   case 4:
+   expr->exthdr.op = NFT_EXTHDR_OP_RT4;
+   break;
}
}
return expr;
@@ -165,6 +168,8 @@ void exthdr_init_raw(struct expr *expr, uint8_t type,
expr->exthdr.desc = _rt0;
else if (op == NFT_EXTHDR_OP_RT2)
expr->exthdr.desc = _rt2;
+   else if (op == NFT_EXTHDR_OP_RT4)
+   expr->exthdr.desc = _rt4;
else if (type < array_size(exthdr_protocols))
expr->exthdr.desc = exthdr_protocols[type];
 
@@ -274,6 +279,24 @@ const struct exthdr_desc exthdr_rt0 = {
},
 };
 
+#define RT4_FIELD(__name, __member, __dtype) \
+   HDR_TEMPLATE(__name, __dtype, struct ip6_rt4, __member)
+
+const struct exthdr_desc exthdr_rt4 = {
+   .name   = "srh",
+   .type   = IPPROTO_ROUTING,
+   .proto_key  = 4,
+   .templates  = {
+   [RT4HDR_LASTENT]= RT4_FIELD("last-entry", 
ip6r4_last_entry, _type),
+   [RT4HDR_FLAGS]  = RT4_FIELD("flags", ip6r4_flags, 
_type),
+   [RT4HDR_TAG]= RT4_FIELD("tag", ip6r4_tag, 
_type),
+   [RT4HDR_SID_1]  = RT4_FIELD("sid[1]", 
ip6r4_segments[0], _type),
+   [RT4HDR_SID_1 + 1]  = RT4_FIELD("sid[1]", 
ip6r4_segments[0], _type),
+   // ...
+   },
+};
+
+
 #define RT_FIELD(__name, __member, __dtype) \
HDR_TEMPLATE(__name, __dtype, struct ip6_rthdr, __member)
 
diff --git a/src/parser_bison.y b/src/parser_bison.y
index df672b1..5fad274 100644
--- a/src/parser_bison.y
+++ b/src/parser_bison.y
@@ -357,8 +357,12 @@ int nft_lex(void *, void *, void *);
 %token RT  "rt"
 %token RT0 "rt0"
 %token RT2 "rt2"
+%token RT4 "srh"
 %token SEG_LEFT"seg-left"
 %token ADDR"addr"
+%token