Blame SOURCES/0059-exthdr-Implement-SCTP-Chunk-matching.patch

cf8614
From 5a8d6197929e30520bb3839c9165d89930888daf Mon Sep 17 00:00:00 2001
cf8614
From: Phil Sutter <psutter@redhat.com>
cf8614
Date: Tue, 13 Jul 2021 13:54:42 +0200
cf8614
Subject: [PATCH] exthdr: Implement SCTP Chunk matching
cf8614
cf8614
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1979334
cf8614
Upstream Status: nftables commit 0e3871cfd9a1e
cf8614
Conflicts:
cf8614
 * Context changes due to missing other scopes.
cf8614
 * Context change due to missing commit 6e6ef00028f1c
cf8614
   ("exthdr: remove tcp dependency for tcp option matching").
cf8614
cf8614
commit 0e3871cfd9a1e32a4ac041ce87a8057b11a89924
cf8614
Author: Phil Sutter <phil@nwl.cc>
cf8614
Date:   Tue May 4 13:41:38 2021 +0200
cf8614
cf8614
    exthdr: Implement SCTP Chunk matching
cf8614
cf8614
    Extend exthdr expression to support scanning through SCTP packet chunks
cf8614
    and matching on fixed fields' values.
cf8614
cf8614
    Signed-off-by: Phil Sutter <phil@nwl.cc>
cf8614
    Acked-by: Florian Westphal <fw@strlen.de>
cf8614
---
cf8614
 doc/libnftables-json.adoc           |  13 +
cf8614
 doc/payload-expression.txt          |  53 +++
cf8614
 include/linux/netfilter/nf_tables.h |   2 +
cf8614
 include/parser.h                    |   1 +
cf8614
 include/sctp_chunk.h                |  87 +++++
cf8614
 src/Makefile.am                     |   1 +
cf8614
 src/evaluate.c                      |   2 +
cf8614
 src/exthdr.c                        |   8 +
cf8614
 src/json.c                          |   2 +
cf8614
 src/parser_bison.y                  | 148 ++++++++-
cf8614
 src/parser_json.c                   |  49 +++
cf8614
 src/scanner.l                       |  38 +++
cf8614
 src/sctp_chunk.c                    | 261 +++++++++++++++
cf8614
 tests/py/inet/sctp.t                |  37 +++
cf8614
 tests/py/inet/sctp.t.json           | 478 ++++++++++++++++++++++++++++
cf8614
 tests/py/inet/sctp.t.payload        | 155 +++++++++
cf8614
 16 files changed, 1333 insertions(+), 2 deletions(-)
cf8614
 create mode 100644 include/sctp_chunk.h
cf8614
 create mode 100644 src/sctp_chunk.c
cf8614
cf8614
diff --git a/doc/libnftables-json.adoc b/doc/libnftables-json.adoc
cf8614
index 858abbf..fba4cb0 100644
cf8614
--- a/doc/libnftables-json.adoc
cf8614
+++ b/doc/libnftables-json.adoc
cf8614
@@ -1200,6 +1200,19 @@ Create a reference to a field (*field*) of a TCP option header (*name*).
cf8614
 If the *field* property is not given, the expression is to be used as a TCP option
cf8614
 existence check in a *match* statement with a boolean on the right hand side.
cf8614
 
cf8614
+=== SCTP CHUNK
cf8614
+[verse]
cf8614
+*{ "sctp chunk": {
cf8614
+	"name":* 'STRING'*,
cf8614
+	"field":* 'STRING'
cf8614
+*}}*
cf8614
+
cf8614
+Create a reference to a field (*field*) of an SCTP chunk (*name*).
cf8614
+
cf8614
+If the *field* property is not given, the expression is to be used as an SCTP
cf8614
+chunk existence check in a *match* statement with a boolean on the right hand
cf8614
+side.
cf8614
+
cf8614
 === META
cf8614
 [verse]
cf8614
 ____
cf8614
diff --git a/doc/payload-expression.txt b/doc/payload-expression.txt
cf8614
index b6d2a28..bd03ca2 100644
cf8614
--- a/doc/payload-expression.txt
cf8614
+++ b/doc/payload-expression.txt
cf8614
@@ -369,7 +369,33 @@ integer (16 bit)
cf8614
 SCTP HEADER EXPRESSION
cf8614
 ~~~~~~~~~~~~~~~~~~~~~~~
cf8614
 [verse]
cf8614
+____
cf8614
 *sctp* {*sport* | *dport* | *vtag* | *checksum*}
cf8614
+*sctp chunk* 'CHUNK' [ 'FIELD' ]
cf8614
+
cf8614
+'CHUNK' := *data* | *init* | *init-ack* | *sack* | *heartbeat* |
cf8614
+	   *heartbeat-ack* | *abort* | *shutdown* | *shutdown-ack* | *error* |
cf8614
+	   *cookie-echo* | *cookie-ack* | *ecne* | *cwr* | *shutdown-complete*
cf8614
+	   | *asconf-ack* | *forward-tsn* | *asconf*
cf8614
+
cf8614
+'FIELD' := 'COMMON_FIELD' | 'DATA_FIELD' | 'INIT_FIELD' | 'INIT_ACK_FIELD' |
cf8614
+	   'SACK_FIELD' | 'SHUTDOWN_FIELD' | 'ECNE_FIELD' | 'CWR_FIELD' |
cf8614
+	   'ASCONF_ACK_FIELD' | 'FORWARD_TSN_FIELD' | 'ASCONF_FIELD'
cf8614
+
cf8614
+'COMMON_FIELD' := *type* | *flags* | *length*
cf8614
+'DATA_FIELD' := *tsn* | *stream* | *ssn* | *ppid*
cf8614
+'INIT_FIELD' := *init-tag* | *a-rwnd* | *num-outbound-streams* |
cf8614
+		*num-inbound-streams* | *initial-tsn*
cf8614
+'INIT_ACK_FIELD' := 'INIT_FIELD'
cf8614
+'SACK_FIELD' := *cum-tsn-ack* | *a-rwnd* | *num-gap-ack-blocks* |
cf8614
+		*num-dup-tsns*
cf8614
+'SHUTDOWN_FIELD' := *cum-tsn-ack*
cf8614
+'ECNE_FIELD' := *lowest-tsn*
cf8614
+'CWR_FIELD' := *lowest-tsn*
cf8614
+'ASCONF_ACK_FIELD' := *seqno*
cf8614
+'FORWARD_TSN_FIELD' := *new-cum-tsn*
cf8614
+'ASCONF_FIELD' := *seqno*
cf8614
+____
cf8614
 
cf8614
 .SCTP header expression
cf8614
 [options="header"]
cf8614
@@ -387,8 +413,35 @@ integer (32 bit)
cf8614
 |checksum|
cf8614
 Checksum|
cf8614
 integer (32 bit)
cf8614
+|chunk|
cf8614
+Search chunk in packet|
cf8614
+without 'FIELD', boolean indicating existence
cf8614
 |================
cf8614
 
cf8614
+.SCTP chunk fields
cf8614
+[options="header"]
cf8614
+|==================
cf8614
+|Name| Width in bits | Chunk | Notes
cf8614
+|type| 8 | all | not useful, defined by chunk type
cf8614
+|flags| 8 | all | semantics defined on per-chunk basis
cf8614
+|length| 16 | all | length of this chunk in bytes excluding padding
cf8614
+|tsn| 32 | data | transmission sequence number
cf8614
+|stream| 16 | data | stream identifier
cf8614
+|ssn| 16 | data | stream sequence number
cf8614
+|ppid| 32 | data | payload protocol identifier
cf8614
+|init-tag| 32 | init, init-ack | initiate tag
cf8614
+|a-rwnd| 32 | init, init-ack, sack | advertised receiver window credit
cf8614
+|num-outbound-streams| 16 | init, init-ack | number of outbound streams
cf8614
+|num-inbound-streams| 16 | init, init-ack | number of inbound streams
cf8614
+|initial-tsn| 32 | init, init-ack | initial transmit sequence number
cf8614
+|cum-tsn-ack| 32 | sack, shutdown | cumulative transmission sequence number acknowledged
cf8614
+|num-gap-ack-blocks| 16 | sack | number of Gap Ack Blocks included
cf8614
+|num-dup-tsns| 16 | sack | number of duplicate transmission sequence numbers received
cf8614
+|lowest-tsn| 32 | ecne, cwr | lowest transmission sequence number
cf8614
+|seqno| 32 | asconf-ack, asconf | sequence number
cf8614
+|new-cum-tsn| 32 | forward-tsn | new cumulative transmission sequence number
cf8614
+|==================
cf8614
+
cf8614
 DCCP HEADER EXPRESSION
cf8614
 ~~~~~~~~~~~~~~~~~~~~~~
cf8614
 [verse]
cf8614
diff --git a/include/linux/netfilter/nf_tables.h b/include/linux/netfilter/nf_tables.h
cf8614
index 1328b8e..960a5b4 100644
cf8614
--- a/include/linux/netfilter/nf_tables.h
cf8614
+++ b/include/linux/netfilter/nf_tables.h
cf8614
@@ -755,11 +755,13 @@ enum nft_exthdr_flags {
cf8614
  * @NFT_EXTHDR_OP_IPV6: match against ipv6 extension headers
cf8614
  * @NFT_EXTHDR_OP_TCP: match against tcp options
cf8614
  * @NFT_EXTHDR_OP_IPV4: match against ipv4 options
cf8614
+ * @NFT_EXTHDR_OP_SCTP: match against sctp chunks
cf8614
  */
cf8614
 enum nft_exthdr_op {
cf8614
 	NFT_EXTHDR_OP_IPV6,
cf8614
 	NFT_EXTHDR_OP_TCPOPT,
cf8614
 	NFT_EXTHDR_OP_IPV4,
cf8614
+	NFT_EXTHDR_OP_SCTP,
cf8614
 	__NFT_EXTHDR_OP_MAX
cf8614
 };
cf8614
 #define NFT_EXTHDR_OP_MAX	(__NFT_EXTHDR_OP_MAX - 1)
cf8614
diff --git a/include/parser.h b/include/parser.h
cf8614
index 2e6ef4d..99bed3c 100644
cf8614
--- a/include/parser.h
cf8614
+++ b/include/parser.h
cf8614
@@ -33,6 +33,7 @@ enum startcond_type {
cf8614
 	PARSER_SC_SCTP,
cf8614
 	PARSER_SC_EXPR_HASH,
cf8614
 	PARSER_SC_EXPR_NUMGEN,
cf8614
+	PARSER_SC_EXPR_SCTP_CHUNK,
cf8614
 };
cf8614
 
cf8614
 struct mnl_socket;
cf8614
diff --git a/include/sctp_chunk.h b/include/sctp_chunk.h
cf8614
new file mode 100644
cf8614
index 0000000..3819200
cf8614
--- /dev/null
cf8614
+++ b/include/sctp_chunk.h
cf8614
@@ -0,0 +1,87 @@
cf8614
+/*
cf8614
+ * Copyright Red Hat
cf8614
+ *
cf8614
+ * This program is free software; you can redistribute it and/or modify
cf8614
+ * it under the terms of the GNU General Public License version 2 (or any
cf8614
+ * later) as published by the Free Software Foundation.
cf8614
+ */
cf8614
+
cf8614
+#ifndef NFTABLES_SCTP_CHUNK_H
cf8614
+#define NFTABLES_SCTP_CHUNK_H
cf8614
+
cf8614
+/* SCTP chunk types used on wire */
cf8614
+enum sctp_hdr_chunk_types {
cf8614
+	SCTP_CHUNK_TYPE_DATA			= 0,
cf8614
+	SCTP_CHUNK_TYPE_INIT			= 1,
cf8614
+	SCTP_CHUNK_TYPE_INIT_ACK		= 2,
cf8614
+	SCTP_CHUNK_TYPE_SACK			= 3,
cf8614
+	SCTP_CHUNK_TYPE_HEARTBEAT		= 4,
cf8614
+	SCTP_CHUNK_TYPE_HEARTBEAT_ACK		= 5,
cf8614
+	SCTP_CHUNK_TYPE_ABORT			= 6,
cf8614
+	SCTP_CHUNK_TYPE_SHUTDOWN		= 7,
cf8614
+	SCTP_CHUNK_TYPE_SHUTDOWN_ACK		= 8,
cf8614
+	SCTP_CHUNK_TYPE_ERROR			= 9,
cf8614
+	SCTP_CHUNK_TYPE_COOKIE_ECHO		= 10,
cf8614
+	SCTP_CHUNK_TYPE_COOKIE_ACK		= 11,
cf8614
+	SCTP_CHUNK_TYPE_ECNE			= 12,
cf8614
+	SCTP_CHUNK_TYPE_CWR			= 13,
cf8614
+	SCTP_CHUNK_TYPE_SHUTDOWN_COMPLETE	= 14,
cf8614
+	SCTP_CHUNK_TYPE_ASCONF_ACK		= 128,
cf8614
+	SCTP_CHUNK_TYPE_FORWARD_TSN		= 192,
cf8614
+	SCTP_CHUNK_TYPE_ASCONF			= 193,
cf8614
+};
cf8614
+
cf8614
+enum sctp_hdr_chunk_common_fields {
cf8614
+	SCTP_CHUNK_COMMON_TYPE,
cf8614
+	SCTP_CHUNK_COMMON_FLAGS,
cf8614
+	SCTP_CHUNK_COMMON_LENGTH,
cf8614
+	__SCTP_CHUNK_COMMON_MAX,
cf8614
+};
cf8614
+
cf8614
+#define SCTP_CHUNK_START_INDEX	__SCTP_CHUNK_COMMON_MAX
cf8614
+
cf8614
+enum sctp_hdr_chunk_data_fields {
cf8614
+	SCTP_CHUNK_DATA_TSN = SCTP_CHUNK_START_INDEX,
cf8614
+	SCTP_CHUNK_DATA_STREAM,
cf8614
+	SCTP_CHUNK_DATA_SSN,
cf8614
+	SCTP_CHUNK_DATA_PPID,
cf8614
+};
cf8614
+
cf8614
+enum sctp_hdr_chunk_init_fields {
cf8614
+	SCTP_CHUNK_INIT_TAG = SCTP_CHUNK_START_INDEX,
cf8614
+	SCTP_CHUNK_INIT_RWND,
cf8614
+	SCTP_CHUNK_INIT_OSTREAMS,
cf8614
+	SCTP_CHUNK_INIT_ISTREAMS,
cf8614
+	SCTP_CHUNK_INIT_TSN,
cf8614
+};
cf8614
+
cf8614
+enum sctp_hdr_chunk_sack_fields {
cf8614
+	SCTP_CHUNK_SACK_CTSN_ACK = SCTP_CHUNK_START_INDEX,
cf8614
+	SCTP_CHUNK_SACK_RWND,
cf8614
+	SCTP_CHUNK_SACK_GACK_BLOCKS,
cf8614
+	SCTP_CHUNK_SACK_DUP_TSNS,
cf8614
+};
cf8614
+
cf8614
+enum sctp_hdr_chunk_shutdown_fields {
cf8614
+	SCTP_CHUNK_SHUTDOWN_CTSN_ACK = SCTP_CHUNK_START_INDEX,
cf8614
+};
cf8614
+
cf8614
+enum sctp_hdr_chunk_ecne_cwr_fields {
cf8614
+	SCTP_CHUNK_ECNE_CWR_MIN_TSN = SCTP_CHUNK_START_INDEX,
cf8614
+};
cf8614
+
cf8614
+enum sctp_hdr_chunk_asconf_fields {
cf8614
+	SCTP_CHUNK_ASCONF_SEQNO = SCTP_CHUNK_START_INDEX,
cf8614
+};
cf8614
+
cf8614
+enum sctp_hdr_chunk_fwd_tsn_fields {
cf8614
+	SCTP_CHUNK_FORWARD_TSN_NCTSN = SCTP_CHUNK_START_INDEX,
cf8614
+};
cf8614
+
cf8614
+struct expr *sctp_chunk_expr_alloc(const struct location *loc,
cf8614
+				   unsigned int type, unsigned int field);
cf8614
+void sctp_chunk_init_raw(struct expr *expr, uint8_t type, unsigned int off,
cf8614
+			 unsigned int len, uint32_t flags);
cf8614
+const struct exthdr_desc *sctp_chunk_protocol_find(const char *name);
cf8614
+
cf8614
+#endif /* NFTABLES_SCTP_CHUNK_H */
cf8614
diff --git a/src/Makefile.am b/src/Makefile.am
cf8614
index 740c21f..366820b 100644
cf8614
--- a/src/Makefile.am
cf8614
+++ b/src/Makefile.am
cf8614
@@ -64,6 +64,7 @@ libnftables_la_SOURCES =			\
cf8614
 		tcpopt.c			\
cf8614
 		socket.c			\
cf8614
 		print.c				\
cf8614
+		sctp_chunk.c			\
cf8614
 		libnftables.c			\
cf8614
 		libnftables.map
cf8614
 
cf8614
diff --git a/src/evaluate.c b/src/evaluate.c
cf8614
index 99a66c2..00ec20b 100644
cf8614
--- a/src/evaluate.c
cf8614
+++ b/src/evaluate.c
cf8614
@@ -579,6 +579,8 @@ static int expr_evaluate_exthdr(struct eval_ctx *ctx, struct expr **exprp)
cf8614
 		dependency = &proto_tcp;
cf8614
 		pb = PROTO_BASE_TRANSPORT_HDR;
cf8614
 		break;
cf8614
+	case NFT_EXTHDR_OP_SCTP:
cf8614
+		return __expr_evaluate_exthdr(ctx, exprp);
cf8614
 	case NFT_EXTHDR_OP_IPV4:
cf8614
 		dependency = &proto_ip;
cf8614
 		break;
cf8614
diff --git a/src/exthdr.c b/src/exthdr.c
cf8614
index 5c75720..f5689e7 100644
cf8614
--- a/src/exthdr.c
cf8614
+++ b/src/exthdr.c
cf8614
@@ -22,6 +22,7 @@
cf8614
 #include <headers.h>
cf8614
 #include <expression.h>
cf8614
 #include <statement.h>
cf8614
+#include <sctp_chunk.h>
cf8614
 
cf8614
 static void exthdr_expr_print(const struct expr *expr, struct output_ctx *octx)
cf8614
 {
cf8614
@@ -55,6 +56,11 @@ static void exthdr_expr_print(const struct expr *expr, struct output_ctx *octx)
cf8614
 		if (expr->exthdr.flags & NFT_EXTHDR_F_PRESENT)
cf8614
 			return;
cf8614
 		nft_print(octx, " %s", expr->exthdr.tmpl->token);
cf8614
+	} else if (expr->exthdr.op == NFT_EXTHDR_OP_SCTP) {
cf8614
+		nft_print(octx, "sctp chunk %s", expr->exthdr.desc->name);
cf8614
+		if (expr->exthdr.flags & NFT_EXTHDR_F_PRESENT)
cf8614
+			return;
cf8614
+		nft_print(octx, " %s", expr->exthdr.tmpl->token);
cf8614
 	} else {
cf8614
 		if (expr->exthdr.flags & NFT_EXTHDR_F_PRESENT)
cf8614
 			nft_print(octx, "exthdr %s", expr->exthdr.desc->name);
cf8614
@@ -197,6 +203,8 @@ void exthdr_init_raw(struct expr *expr, uint8_t type,
cf8614
 		return tcpopt_init_raw(expr, type, offset, len, flags);
cf8614
 	if (op == NFT_EXTHDR_OP_IPV4)
cf8614
 		return ipopt_init_raw(expr, type, offset, len, flags, true);
cf8614
+	if (op == NFT_EXTHDR_OP_SCTP)
cf8614
+		return sctp_chunk_init_raw(expr, type, offset, len, flags);
cf8614
 
cf8614
 	expr->len = len;
cf8614
 	expr->exthdr.flags = flags;
cf8614
diff --git a/src/json.c b/src/json.c
cf8614
index a6d0716..dfc9031 100644
cf8614
--- a/src/json.c
cf8614
+++ b/src/json.c
cf8614
@@ -692,6 +692,8 @@ json_t *exthdr_expr_json(const struct expr *expr, struct output_ctx *octx)
cf8614
 	switch (expr->exthdr.op) {
cf8614
 	case NFT_EXTHDR_OP_IPV4:
cf8614
 		return json_pack("{s:o}", "ip option", root);
cf8614
+	case NFT_EXTHDR_OP_SCTP:
cf8614
+		return json_pack("{s:o}", "sctp chunk", root);
cf8614
 	default:
cf8614
 		return json_pack("{s:o}", "exthdr", root);
cf8614
 	}
cf8614
diff --git a/src/parser_bison.y b/src/parser_bison.y
cf8614
index beb5995..5ab5744 100644
cf8614
--- a/src/parser_bison.y
cf8614
+++ b/src/parser_bison.y
cf8614
@@ -38,6 +38,7 @@
cf8614
 #include <utils.h>
cf8614
 #include <parser.h>
cf8614
 #include <erec.h>
cf8614
+#include <sctp_chunk.h>
cf8614
 
cf8614
 #include "parser_bison.h"
cf8614
 
cf8614
@@ -402,6 +403,40 @@ int nft_lex(void *, void *, void *);
cf8614
 %token DCCP			"dccp"
cf8614
 
cf8614
 %token SCTP			"sctp"
cf8614
+%token CHUNK			"chunk"
cf8614
+%token DATA			"data"
cf8614
+%token INIT			"init"
cf8614
+%token INIT_ACK			"init-ack"
cf8614
+%token HEARTBEAT		"heartbeat"
cf8614
+%token HEARTBEAT_ACK		"heartbeat-ack"
cf8614
+%token ABORT			"abort"
cf8614
+%token SHUTDOWN			"shutdown"
cf8614
+%token SHUTDOWN_ACK		"shutdown-ack"
cf8614
+%token ERROR			"error"
cf8614
+%token COOKIE_ECHO		"cookie-echo"
cf8614
+%token COOKIE_ACK		"cookie-ack"
cf8614
+%token ECNE			"ecne"
cf8614
+%token CWR			"cwr"
cf8614
+%token SHUTDOWN_COMPLETE	"shutdown-complete"
cf8614
+%token ASCONF_ACK		"asconf-ack"
cf8614
+%token FORWARD_TSN		"forward-tsn"
cf8614
+%token ASCONF			"asconf"
cf8614
+%token TSN			"tsn"
cf8614
+%token STREAM			"stream"
cf8614
+%token SSN			"ssn"
cf8614
+%token PPID			"ppid"
cf8614
+%token INIT_TAG			"init-tag"
cf8614
+%token A_RWND			"a-rwnd"
cf8614
+%token NUM_OSTREAMS		"num-outbound-streams"
cf8614
+%token NUM_ISTREAMS		"num-inbound-streams"
cf8614
+%token INIT_TSN			"initial-tsn"
cf8614
+%token CUM_TSN_ACK		"cum-tsn-ack"
cf8614
+%token NUM_GACK_BLOCKS		"num-gap-ack-blocks"
cf8614
+%token NUM_DUP_TSNS		"num-dup-tsns"
cf8614
+%token LOWEST_TSN		"lowest-tsn"
cf8614
+%token SEQNO			"seqno"
cf8614
+%token NEW_CUM_TSN		"new-cum-tsn"
cf8614
+
cf8614
 %token VTAG			"vtag"
cf8614
 
cf8614
 %token RT			"rt"
cf8614
@@ -746,9 +781,12 @@ int nft_lex(void *, void *, void *);
cf8614
 %type <expr>			udp_hdr_expr	udplite_hdr_expr
cf8614
 %destructor { expr_free($$); }	udp_hdr_expr	udplite_hdr_expr
cf8614
 %type <val>			udp_hdr_field	udplite_hdr_field
cf8614
-%type <expr>			dccp_hdr_expr	sctp_hdr_expr
cf8614
-%destructor { expr_free($$); }	dccp_hdr_expr	sctp_hdr_expr
cf8614
+%type <expr>			dccp_hdr_expr	sctp_hdr_expr sctp_chunk_alloc
cf8614
+%destructor { expr_free($$); }	dccp_hdr_expr	sctp_hdr_expr sctp_chunk_alloc
cf8614
 %type <val>			dccp_hdr_field	sctp_hdr_field
cf8614
+%type <val>			sctp_chunk_type sctp_chunk_common_field
cf8614
+%type <val>			sctp_chunk_data_field sctp_chunk_init_field
cf8614
+%type <val>			sctp_chunk_sack_field
cf8614
 %type <expr>			th_hdr_expr
cf8614
 %destructor { expr_free($$); }	th_hdr_expr
cf8614
 %type <val>			th_hdr_field
cf8614
@@ -843,6 +881,7 @@ opt_newline		:	NEWLINE
cf8614
 close_scope_hash	: { scanner_pop_start_cond(nft->scanner, PARSER_SC_EXPR_HASH); };
cf8614
 close_scope_numgen	: { scanner_pop_start_cond(nft->scanner, PARSER_SC_EXPR_NUMGEN); };
cf8614
 close_scope_sctp	: { scanner_pop_start_cond(nft->scanner, PARSER_SC_SCTP); };
cf8614
+close_scope_sctp_chunk	: { scanner_pop_start_cond(nft->scanner, PARSER_SC_EXPR_SCTP_CHUNK); };
cf8614
 
cf8614
 common_block		:	INCLUDE		QUOTED_STRING	stmt_separator
cf8614
 			{
cf8614
@@ -4783,10 +4822,115 @@ dccp_hdr_field		:	SPORT		{ $$ = DCCPHDR_SPORT; }
cf8614
 			|	TYPE		{ $$ = DCCPHDR_TYPE; }
cf8614
 			;
cf8614
 
cf8614
+sctp_chunk_type		:	DATA		{ $$ = SCTP_CHUNK_TYPE_DATA; }
cf8614
+			|	INIT		{ $$ = SCTP_CHUNK_TYPE_INIT; }
cf8614
+			|	INIT_ACK	{ $$ = SCTP_CHUNK_TYPE_INIT_ACK; }
cf8614
+			|	SACK		{ $$ = SCTP_CHUNK_TYPE_SACK; }
cf8614
+			|	HEARTBEAT	{ $$ = SCTP_CHUNK_TYPE_HEARTBEAT; }
cf8614
+			|	HEARTBEAT_ACK	{ $$ = SCTP_CHUNK_TYPE_HEARTBEAT_ACK; }
cf8614
+			|	ABORT		{ $$ = SCTP_CHUNK_TYPE_ABORT; }
cf8614
+			|	SHUTDOWN	{ $$ = SCTP_CHUNK_TYPE_SHUTDOWN; }
cf8614
+			|	SHUTDOWN_ACK	{ $$ = SCTP_CHUNK_TYPE_SHUTDOWN_ACK; }
cf8614
+			|	ERROR		{ $$ = SCTP_CHUNK_TYPE_ERROR; }
cf8614
+			|	COOKIE_ECHO	{ $$ = SCTP_CHUNK_TYPE_COOKIE_ECHO; }
cf8614
+			|	COOKIE_ACK	{ $$ = SCTP_CHUNK_TYPE_COOKIE_ACK; }
cf8614
+			|	ECNE		{ $$ = SCTP_CHUNK_TYPE_ECNE; }
cf8614
+			|	CWR		{ $$ = SCTP_CHUNK_TYPE_CWR; }
cf8614
+			|	SHUTDOWN_COMPLETE { $$ = SCTP_CHUNK_TYPE_SHUTDOWN_COMPLETE; }
cf8614
+			|	ASCONF_ACK	{ $$ = SCTP_CHUNK_TYPE_ASCONF_ACK; }
cf8614
+			|	FORWARD_TSN	{ $$ = SCTP_CHUNK_TYPE_FORWARD_TSN; }
cf8614
+			|	ASCONF		{ $$ = SCTP_CHUNK_TYPE_ASCONF; }
cf8614
+			;
cf8614
+
cf8614
+sctp_chunk_common_field	:	TYPE	{ $$ = SCTP_CHUNK_COMMON_TYPE; }
cf8614
+			|	FLAGS	{ $$ = SCTP_CHUNK_COMMON_FLAGS; }
cf8614
+			|	LENGTH	{ $$ = SCTP_CHUNK_COMMON_LENGTH; }
cf8614
+			;
cf8614
+
cf8614
+sctp_chunk_data_field	:	TSN	{ $$ = SCTP_CHUNK_DATA_TSN; }
cf8614
+			|	STREAM	{ $$ = SCTP_CHUNK_DATA_STREAM; }
cf8614
+			|	SSN	{ $$ = SCTP_CHUNK_DATA_SSN; }
cf8614
+			|	PPID	{ $$ = SCTP_CHUNK_DATA_PPID; }
cf8614
+			;
cf8614
+
cf8614
+sctp_chunk_init_field	:	INIT_TAG	{ $$ = SCTP_CHUNK_INIT_TAG; }
cf8614
+			|	A_RWND		{ $$ = SCTP_CHUNK_INIT_RWND; }
cf8614
+			|	NUM_OSTREAMS	{ $$ = SCTP_CHUNK_INIT_OSTREAMS; }
cf8614
+			|	NUM_ISTREAMS	{ $$ = SCTP_CHUNK_INIT_ISTREAMS; }
cf8614
+			|	INIT_TSN	{ $$ = SCTP_CHUNK_INIT_TSN; }
cf8614
+			;
cf8614
+
cf8614
+sctp_chunk_sack_field	:	CUM_TSN_ACK	{ $$ = SCTP_CHUNK_SACK_CTSN_ACK; }
cf8614
+			|	A_RWND		{ $$ = SCTP_CHUNK_SACK_RWND; }
cf8614
+			|	NUM_GACK_BLOCKS	{ $$ = SCTP_CHUNK_SACK_GACK_BLOCKS; }
cf8614
+			|	NUM_DUP_TSNS	{ $$ = SCTP_CHUNK_SACK_DUP_TSNS; }
cf8614
+			;
cf8614
+
cf8614
+sctp_chunk_alloc	:	sctp_chunk_type
cf8614
+			{
cf8614
+				$$ = sctp_chunk_expr_alloc(&@$, $1, SCTP_CHUNK_COMMON_TYPE);
cf8614
+				$$->exthdr.flags = NFT_EXTHDR_F_PRESENT;
cf8614
+			}
cf8614
+			|	sctp_chunk_type	sctp_chunk_common_field
cf8614
+			{
cf8614
+				$$ = sctp_chunk_expr_alloc(&@$, $1, $2);
cf8614
+			}
cf8614
+			|	DATA	sctp_chunk_data_field
cf8614
+			{
cf8614
+				$$ = sctp_chunk_expr_alloc(&@$, SCTP_CHUNK_TYPE_DATA, $2);
cf8614
+			}
cf8614
+			|	INIT	sctp_chunk_init_field
cf8614
+			{
cf8614
+				$$ = sctp_chunk_expr_alloc(&@$, SCTP_CHUNK_TYPE_INIT, $2);
cf8614
+			}
cf8614
+			|	INIT_ACK	sctp_chunk_init_field
cf8614
+			{
cf8614
+				$$ = sctp_chunk_expr_alloc(&@$, SCTP_CHUNK_TYPE_INIT_ACK, $2);
cf8614
+			}
cf8614
+			|	SACK	sctp_chunk_sack_field
cf8614
+			{
cf8614
+				$$ = sctp_chunk_expr_alloc(&@$, SCTP_CHUNK_TYPE_SACK, $2);
cf8614
+			}
cf8614
+			|	SHUTDOWN	CUM_TSN_ACK
cf8614
+			{
cf8614
+				$$ = sctp_chunk_expr_alloc(&@$, SCTP_CHUNK_TYPE_SHUTDOWN,
cf8614
+							   SCTP_CHUNK_SHUTDOWN_CTSN_ACK);
cf8614
+			}
cf8614
+			|	ECNE	LOWEST_TSN
cf8614
+			{
cf8614
+				$$ = sctp_chunk_expr_alloc(&@$, SCTP_CHUNK_TYPE_ECNE,
cf8614
+							   SCTP_CHUNK_ECNE_CWR_MIN_TSN);
cf8614
+			}
cf8614
+			|	CWR	LOWEST_TSN
cf8614
+			{
cf8614
+				$$ = sctp_chunk_expr_alloc(&@$, SCTP_CHUNK_TYPE_CWR,
cf8614
+							   SCTP_CHUNK_ECNE_CWR_MIN_TSN);
cf8614
+			}
cf8614
+			|	ASCONF_ACK	SEQNO
cf8614
+			{
cf8614
+				$$ = sctp_chunk_expr_alloc(&@$, SCTP_CHUNK_TYPE_ASCONF_ACK,
cf8614
+							   SCTP_CHUNK_ASCONF_SEQNO);
cf8614
+			}
cf8614
+			|	FORWARD_TSN	NEW_CUM_TSN
cf8614
+			{
cf8614
+				$$ = sctp_chunk_expr_alloc(&@$, SCTP_CHUNK_TYPE_FORWARD_TSN,
cf8614
+							   SCTP_CHUNK_FORWARD_TSN_NCTSN);
cf8614
+			}
cf8614
+			|	ASCONF	SEQNO
cf8614
+			{
cf8614
+				$$ = sctp_chunk_expr_alloc(&@$, SCTP_CHUNK_TYPE_ASCONF,
cf8614
+							   SCTP_CHUNK_ASCONF_SEQNO);
cf8614
+			}
cf8614
+			;
cf8614
+
cf8614
 sctp_hdr_expr		:	SCTP	sctp_hdr_field	close_scope_sctp
cf8614
 			{
cf8614
 				$$ = payload_expr_alloc(&@$, &proto_sctp, $2);
cf8614
 			}
cf8614
+			|	SCTP	CHUNK	sctp_chunk_alloc close_scope_sctp_chunk close_scope_sctp
cf8614
+			{
cf8614
+				$$ = $3;
cf8614
+			}
cf8614
 			;
cf8614
 
cf8614
 sctp_hdr_field		:	SPORT		{ $$ = SCTPHDR_SPORT; }
cf8614
diff --git a/src/parser_json.c b/src/parser_json.c
cf8614
index fbf7db5..a069a89 100644
cf8614
--- a/src/parser_json.c
cf8614
+++ b/src/parser_json.c
cf8614
@@ -11,6 +11,7 @@
cf8614
 #include <netlink.h>
cf8614
 #include <parser.h>
cf8614
 #include <rule.h>
cf8614
+#include <sctp_chunk.h>
cf8614
 #include <socket.h>
cf8614
 
cf8614
 #include <netdb.h>
cf8614
@@ -705,6 +706,53 @@ static struct expr *json_parse_ip_option_expr(struct json_ctx *ctx,
cf8614
 	return ipopt_expr_alloc(int_loc, descval, fieldval, 0);
cf8614
 }
cf8614
 
cf8614
+static int json_parse_sctp_chunk_field(const struct exthdr_desc *desc,
cf8614
+				       const char *name, int *val)
cf8614
+{
cf8614
+	unsigned int i;
cf8614
+
cf8614
+	for (i = 0; i < array_size(desc->templates); i++) {
cf8614
+		if (desc->templates[i].token &&
cf8614
+		    !strcmp(desc->templates[i].token, name)) {
cf8614
+			if (val)
cf8614
+				*val = i;
cf8614
+			return 0;
cf8614
+		}
cf8614
+	}
cf8614
+	return 1;
cf8614
+}
cf8614
+
cf8614
+static struct expr *json_parse_sctp_chunk_expr(struct json_ctx *ctx,
cf8614
+					       const char *type, json_t *root)
cf8614
+{
cf8614
+	const struct exthdr_desc *desc;
cf8614
+	const char *name, *field;
cf8614
+	struct expr *expr;
cf8614
+	int fieldval;
cf8614
+
cf8614
+	if (json_unpack_err(ctx, root, "{s:s}", "name", &name))
cf8614
+		return NULL;
cf8614
+
cf8614
+	desc = sctp_chunk_protocol_find(name);
cf8614
+	if (!desc) {
cf8614
+		json_error(ctx, "Unknown sctp chunk name '%s'.", name);
cf8614
+		return NULL;
cf8614
+	}
cf8614
+
cf8614
+	if (json_unpack(root, "{s:s}", "field", &field)) {
cf8614
+		expr = sctp_chunk_expr_alloc(int_loc, desc->type,
cf8614
+					     SCTP_CHUNK_COMMON_TYPE);
cf8614
+		expr->exthdr.flags = NFT_EXTHDR_F_PRESENT;
cf8614
+
cf8614
+		return expr;
cf8614
+	}
cf8614
+	if (json_parse_sctp_chunk_field(desc, field, &fieldval)) {
cf8614
+		json_error(ctx, "Unknown sctp chunk field '%s'.", field);
cf8614
+		return NULL;
cf8614
+	}
cf8614
+	return sctp_chunk_expr_alloc(int_loc, desc->type, fieldval);
cf8614
+}
cf8614
+
cf8614
 static const struct exthdr_desc *exthdr_lookup_byname(const char *name)
cf8614
 {
cf8614
 	const struct exthdr_desc *exthdr_tbl[] = {
cf8614
@@ -1410,6 +1458,7 @@ static struct expr *json_parse_expr(struct json_ctx *ctx, json_t *root)
cf8614
 		{ "exthdr", json_parse_exthdr_expr, CTX_F_PRIMARY | CTX_F_SET_RHS | CTX_F_SES | CTX_F_MAP | CTX_F_CONCAT },
cf8614
 		{ "tcp option", json_parse_tcp_option_expr, CTX_F_PRIMARY | CTX_F_SET_RHS | CTX_F_MANGLE | CTX_F_SES | CTX_F_CONCAT },
cf8614
 		{ "ip option", json_parse_ip_option_expr, CTX_F_PRIMARY | CTX_F_SET_RHS | CTX_F_MANGLE | CTX_F_SES | CTX_F_CONCAT },
cf8614
+		{ "sctp chunk", json_parse_sctp_chunk_expr, CTX_F_PRIMARY | CTX_F_SET_RHS | CTX_F_MANGLE | CTX_F_SES | CTX_F_CONCAT },
cf8614
 		{ "meta", json_parse_meta_expr, CTX_F_STMT | CTX_F_PRIMARY | CTX_F_SET_RHS | CTX_F_MANGLE | CTX_F_SES | CTX_F_MAP | CTX_F_CONCAT },
cf8614
 		{ "osf", json_parse_osf_expr, CTX_F_STMT | CTX_F_PRIMARY | CTX_F_MAP | CTX_F_CONCAT },
cf8614
 		{ "ipsec", json_parse_xfrm_expr, CTX_F_PRIMARY | CTX_F_MAP | CTX_F_CONCAT },
cf8614
diff --git a/src/scanner.l b/src/scanner.l
cf8614
index b79ae55..fe1b8ad 100644
cf8614
--- a/src/scanner.l
cf8614
+++ b/src/scanner.l
cf8614
@@ -199,6 +199,7 @@ addrstring	({macaddr}|{ip4addr}|{ip6addr})
cf8614
 %s SCANSTATE_SCTP
cf8614
 %s SCANSTATE_EXPR_HASH
cf8614
 %s SCANSTATE_EXPR_NUMGEN
cf8614
+%s SCANSTATE_EXPR_SCTP_CHUNK
cf8614
 
cf8614
 %%
cf8614
 
cf8614
@@ -492,9 +493,46 @@ addrstring	({macaddr}|{ip4addr}|{ip6addr})
cf8614
 "sctp"			{ scanner_push_start_cond(yyscanner, SCANSTATE_SCTP); return SCTP; }
cf8614
 
cf8614
 <SCANSTATE_SCTP>{
cf8614
+	"chunk"			{ scanner_push_start_cond(yyscanner, SCANSTATE_EXPR_SCTP_CHUNK); return CHUNK; }
cf8614
 	"vtag"			{ return VTAG; }
cf8614
 }
cf8614
 
cf8614
+<SCANSTATE_EXPR_SCTP_CHUNK>{
cf8614
+	"data"			{ return DATA; }
cf8614
+	"init"			{ return INIT; }
cf8614
+	"init-ack"		{ return INIT_ACK; }
cf8614
+	"heartbeat"		{ return HEARTBEAT; }
cf8614
+	"heartbeat-ack"		{ return HEARTBEAT_ACK; }
cf8614
+	"abort"			{ return ABORT; }
cf8614
+	"shutdown"		{ return SHUTDOWN; }
cf8614
+	"shutdown-ack"		{ return SHUTDOWN_ACK; }
cf8614
+	"error"			{ return ERROR; }
cf8614
+	"cookie-echo"		{ return COOKIE_ECHO; }
cf8614
+	"cookie-ack"		{ return COOKIE_ACK; }
cf8614
+	"ecne"			{ return ECNE; }
cf8614
+	"cwr"			{ return CWR; }
cf8614
+	"shutdown-complete"	{ return SHUTDOWN_COMPLETE; }
cf8614
+	"asconf-ack"		{ return ASCONF_ACK; }
cf8614
+	"forward-tsn"		{ return FORWARD_TSN; }
cf8614
+	"asconf"		{ return ASCONF; }
cf8614
+
cf8614
+	"tsn"			{ return TSN; }
cf8614
+	"stream"		{ return STREAM; }
cf8614
+	"ssn"			{ return SSN; }
cf8614
+	"ppid"			{ return PPID; }
cf8614
+	"init-tag"		{ return INIT_TAG; }
cf8614
+	"a-rwnd"		{ return A_RWND; }
cf8614
+	"num-outbound-streams"	{ return NUM_OSTREAMS; }
cf8614
+	"num-inbound-streams"	{ return NUM_ISTREAMS; }
cf8614
+	"initial-tsn"		{ return INIT_TSN; }
cf8614
+	"cum-tsn-ack"		{ return CUM_TSN_ACK; }
cf8614
+	"num-gap-ack-blocks"	{ return NUM_GACK_BLOCKS; }
cf8614
+	"num-dup-tsns"		{ return NUM_DUP_TSNS; }
cf8614
+	"lowest-tsn"		{ return LOWEST_TSN; }
cf8614
+	"seqno"			{ return SEQNO; }
cf8614
+	"new-cum-tsn"		{ return NEW_CUM_TSN; }
cf8614
+}
cf8614
+
cf8614
 "rt"			{ return RT; }
cf8614
 "rt0"			{ return RT0; }
cf8614
 "rt2"			{ return RT2; }
cf8614
diff --git a/src/sctp_chunk.c b/src/sctp_chunk.c
cf8614
new file mode 100644
cf8614
index 0000000..6e73e72
cf8614
--- /dev/null
cf8614
+++ b/src/sctp_chunk.c
cf8614
@@ -0,0 +1,261 @@
cf8614
+/*
cf8614
+ * Copyright Red Hat
cf8614
+ *
cf8614
+ * This program is free software; you can redistribute it and/or modify
cf8614
+ * it under the terms of the GNU General Public License version 2 (or any
cf8614
+ * later) as published by the Free Software Foundation.
cf8614
+ */
cf8614
+
cf8614
+#include <exthdr.h>
cf8614
+#include <sctp_chunk.h>
cf8614
+
cf8614
+#include <string.h>
cf8614
+
cf8614
+#define PHT(__token, __offset, __len) \
cf8614
+	PROTO_HDR_TEMPLATE(__token, &integer_type, BYTEORDER_BIG_ENDIAN, \
cf8614
+			   __offset, __len)
cf8614
+
cf8614
+static const struct exthdr_desc sctp_chunk_data = {
cf8614
+	.name	= "data",
cf8614
+	.type	= SCTP_CHUNK_TYPE_DATA,
cf8614
+	.templates = {
cf8614
+		[SCTP_CHUNK_COMMON_TYPE]	= PHT("type", 0, 8),
cf8614
+		[SCTP_CHUNK_COMMON_FLAGS]	= PHT("flags", 8, 8),
cf8614
+		[SCTP_CHUNK_COMMON_LENGTH]	= PHT("length", 16, 16),
cf8614
+		[SCTP_CHUNK_DATA_TSN]		= PHT("tsn", 32, 32),
cf8614
+		[SCTP_CHUNK_DATA_STREAM]	= PHT("stream", 64, 16),
cf8614
+		[SCTP_CHUNK_DATA_SSN]		= PHT("ssn", 80, 16),
cf8614
+		[SCTP_CHUNK_DATA_PPID]		= PHT("ppid", 96, 32),
cf8614
+	},
cf8614
+};
cf8614
+
cf8614
+static const struct exthdr_desc sctp_chunk_init = {
cf8614
+	.name	= "init",
cf8614
+	.type	= SCTP_CHUNK_TYPE_INIT,
cf8614
+	.templates = {
cf8614
+		[SCTP_CHUNK_COMMON_TYPE]	= PHT("type", 0, 8),
cf8614
+		[SCTP_CHUNK_COMMON_FLAGS]	= PHT("flags", 8, 8),
cf8614
+		[SCTP_CHUNK_COMMON_LENGTH]	= PHT("length", 16, 16),
cf8614
+		[SCTP_CHUNK_INIT_TAG]		= PHT("init-tag", 32, 32),
cf8614
+		[SCTP_CHUNK_INIT_RWND]		= PHT("a-rwnd", 64, 32),
cf8614
+		[SCTP_CHUNK_INIT_OSTREAMS]	= PHT("num-outbound-streams", 96, 16),
cf8614
+		[SCTP_CHUNK_INIT_ISTREAMS]	= PHT("num-inbound-streams", 112, 16),
cf8614
+		[SCTP_CHUNK_INIT_TSN]		= PHT("initial-tsn", 128, 32),
cf8614
+	},
cf8614
+};
cf8614
+
cf8614
+static const struct exthdr_desc sctp_chunk_init_ack = {
cf8614
+	.name	= "init-ack",
cf8614
+	.type	= SCTP_CHUNK_TYPE_INIT_ACK,
cf8614
+	.templates = {
cf8614
+		[SCTP_CHUNK_COMMON_TYPE]	= PHT("type", 0, 8),
cf8614
+		[SCTP_CHUNK_COMMON_FLAGS]	= PHT("flags", 8, 8),
cf8614
+		[SCTP_CHUNK_COMMON_LENGTH]	= PHT("length", 16, 16),
cf8614
+		[SCTP_CHUNK_INIT_TAG]		= PHT("init-tag", 32, 32),
cf8614
+		[SCTP_CHUNK_INIT_RWND]		= PHT("a-rwnd", 64, 32),
cf8614
+		[SCTP_CHUNK_INIT_OSTREAMS]	= PHT("num-outbound-streams", 96, 16),
cf8614
+		[SCTP_CHUNK_INIT_ISTREAMS]	= PHT("num-inbound-streams", 112, 16),
cf8614
+		[SCTP_CHUNK_INIT_TSN]		= PHT("initial-tsn", 128, 32),
cf8614
+	},
cf8614
+};
cf8614
+
cf8614
+static const struct exthdr_desc sctp_chunk_sack = {
cf8614
+	.name	= "sack",
cf8614
+	.type	= SCTP_CHUNK_TYPE_SACK,
cf8614
+	.templates = {
cf8614
+		[SCTP_CHUNK_COMMON_TYPE]	= PHT("type", 0, 8),
cf8614
+		[SCTP_CHUNK_COMMON_FLAGS]	= PHT("flags", 8, 8),
cf8614
+		[SCTP_CHUNK_COMMON_LENGTH]	= PHT("length", 16, 16),
cf8614
+		[SCTP_CHUNK_SACK_CTSN_ACK]	= PHT("cum-tsn-ack", 32, 32),
cf8614
+		[SCTP_CHUNK_SACK_RWND]		= PHT("a-rwnd", 64, 32),
cf8614
+		[SCTP_CHUNK_SACK_GACK_BLOCKS]	= PHT("num-gap-ack-blocks", 96, 16),
cf8614
+		[SCTP_CHUNK_SACK_DUP_TSNS]	= PHT("num-dup-tsns", 112, 16),
cf8614
+	},
cf8614
+};
cf8614
+
cf8614
+static const struct exthdr_desc sctp_chunk_shutdown = {
cf8614
+	.name	= "shutdown",
cf8614
+	.type	= SCTP_CHUNK_TYPE_SHUTDOWN,
cf8614
+	.templates = {
cf8614
+		[SCTP_CHUNK_COMMON_TYPE]	= PHT("type", 0, 8),
cf8614
+		[SCTP_CHUNK_COMMON_FLAGS]	= PHT("flags", 8, 8),
cf8614
+		[SCTP_CHUNK_COMMON_LENGTH]	= PHT("length", 16, 16),
cf8614
+		[SCTP_CHUNK_SHUTDOWN_CTSN_ACK]	= PHT("cum-tsn-ack", 32, 32),
cf8614
+	},
cf8614
+};
cf8614
+
cf8614
+static const struct exthdr_desc sctp_chunk_ecne = {
cf8614
+	.name	= "ecne",
cf8614
+	.type	= SCTP_CHUNK_TYPE_ECNE,
cf8614
+	.templates = {
cf8614
+		[SCTP_CHUNK_COMMON_TYPE]	= PHT("type", 0, 8),
cf8614
+		[SCTP_CHUNK_COMMON_FLAGS]	= PHT("flags", 8, 8),
cf8614
+		[SCTP_CHUNK_COMMON_LENGTH]	= PHT("length", 16, 16),
cf8614
+		[SCTP_CHUNK_ECNE_CWR_MIN_TSN]	= PHT("lowest-tsn", 32, 32),
cf8614
+	},
cf8614
+};
cf8614
+
cf8614
+static const struct exthdr_desc sctp_chunk_cwr = {
cf8614
+	.name	= "cwr",
cf8614
+	.type	= SCTP_CHUNK_TYPE_CWR,
cf8614
+	.templates = {
cf8614
+		[SCTP_CHUNK_COMMON_TYPE]	= PHT("type", 0, 8),
cf8614
+		[SCTP_CHUNK_COMMON_FLAGS]	= PHT("flags", 8, 8),
cf8614
+		[SCTP_CHUNK_COMMON_LENGTH]	= PHT("length", 16, 16),
cf8614
+		[SCTP_CHUNK_ECNE_CWR_MIN_TSN]	= PHT("lowest-tsn", 32, 32),
cf8614
+	},
cf8614
+};
cf8614
+
cf8614
+static const struct exthdr_desc sctp_chunk_asconf_ack = {
cf8614
+	.name	= "asconf-ack",
cf8614
+	.type	= SCTP_CHUNK_TYPE_ASCONF_ACK,
cf8614
+	.templates = {
cf8614
+		[SCTP_CHUNK_COMMON_TYPE]	= PHT("type", 0, 8),
cf8614
+		[SCTP_CHUNK_COMMON_FLAGS]	= PHT("flags", 8, 8),
cf8614
+		[SCTP_CHUNK_COMMON_LENGTH]	= PHT("length", 16, 16),
cf8614
+		[SCTP_CHUNK_ASCONF_SEQNO]	= PHT("seqno", 32, 32),
cf8614
+	},
cf8614
+};
cf8614
+
cf8614
+static const struct exthdr_desc sctp_chunk_forward_tsn = {
cf8614
+	.name	= "forward-tsn",
cf8614
+	.type	= SCTP_CHUNK_TYPE_FORWARD_TSN,
cf8614
+	.templates = {
cf8614
+		[SCTP_CHUNK_COMMON_TYPE]	= PHT("type", 0, 8),
cf8614
+		[SCTP_CHUNK_COMMON_FLAGS]	= PHT("flags", 8, 8),
cf8614
+		[SCTP_CHUNK_COMMON_LENGTH]	= PHT("length", 16, 16),
cf8614
+		[SCTP_CHUNK_FORWARD_TSN_NCTSN]	= PHT("new-cum-tsn", 32, 32),
cf8614
+	},
cf8614
+};
cf8614
+
cf8614
+static const struct exthdr_desc sctp_chunk_asconf = {
cf8614
+	.name	= "asconf",
cf8614
+	.type	= SCTP_CHUNK_TYPE_ASCONF,
cf8614
+	.templates = {
cf8614
+		[SCTP_CHUNK_COMMON_TYPE]	= PHT("type", 0, 8),
cf8614
+		[SCTP_CHUNK_COMMON_FLAGS]	= PHT("flags", 8, 8),
cf8614
+		[SCTP_CHUNK_COMMON_LENGTH]	= PHT("length", 16, 16),
cf8614
+		[SCTP_CHUNK_ASCONF_SEQNO]	= PHT("seqno", 32, 32),
cf8614
+	},
cf8614
+};
cf8614
+
cf8614
+#define SCTP_CHUNK_DESC_GENERATOR(descname, hname, desctype)		\
cf8614
+static const struct exthdr_desc sctp_chunk_##descname = {		\
cf8614
+	.name	= #hname,						\
cf8614
+	.type	= SCTP_CHUNK_TYPE_##desctype,				\
cf8614
+	.templates = {							\
cf8614
+		[SCTP_CHUNK_COMMON_TYPE]	= PHT("type", 0, 8),	\
cf8614
+		[SCTP_CHUNK_COMMON_FLAGS]	= PHT("flags", 8, 8),	\
cf8614
+		[SCTP_CHUNK_COMMON_LENGTH]	= PHT("length", 16, 16),\
cf8614
+	},								\
cf8614
+};
cf8614
+
cf8614
+SCTP_CHUNK_DESC_GENERATOR(heartbeat, heartbeat, HEARTBEAT)
cf8614
+SCTP_CHUNK_DESC_GENERATOR(heartbeat_ack, heartbeat-ack, HEARTBEAT_ACK)
cf8614
+SCTP_CHUNK_DESC_GENERATOR(abort, abort, ABORT)
cf8614
+SCTP_CHUNK_DESC_GENERATOR(shutdown_ack, shutdown-ack, SHUTDOWN_ACK)
cf8614
+SCTP_CHUNK_DESC_GENERATOR(error, error, ERROR)
cf8614
+SCTP_CHUNK_DESC_GENERATOR(cookie_echo, cookie-echo, COOKIE_ECHO)
cf8614
+SCTP_CHUNK_DESC_GENERATOR(cookie_ack, cookie-ack, COOKIE_ACK)
cf8614
+SCTP_CHUNK_DESC_GENERATOR(shutdown_complete, shutdown-complete, SHUTDOWN_COMPLETE)
cf8614
+
cf8614
+#undef SCTP_CHUNK_DESC_GENERATOR
cf8614
+
cf8614
+static const struct exthdr_desc *sctp_chunk_protocols[] = {
cf8614
+	[SCTP_CHUNK_TYPE_DATA]			= &sctp_chunk_data,
cf8614
+	[SCTP_CHUNK_TYPE_INIT]			= &sctp_chunk_init,
cf8614
+	[SCTP_CHUNK_TYPE_INIT_ACK]		= &sctp_chunk_init_ack,
cf8614
+	[SCTP_CHUNK_TYPE_SACK]			= &sctp_chunk_sack,
cf8614
+	[SCTP_CHUNK_TYPE_HEARTBEAT]		= &sctp_chunk_heartbeat,
cf8614
+	[SCTP_CHUNK_TYPE_HEARTBEAT_ACK]		= &sctp_chunk_heartbeat_ack,
cf8614
+	[SCTP_CHUNK_TYPE_ABORT]			= &sctp_chunk_abort,
cf8614
+	[SCTP_CHUNK_TYPE_SHUTDOWN]		= &sctp_chunk_shutdown,
cf8614
+	[SCTP_CHUNK_TYPE_SHUTDOWN_ACK]		= &sctp_chunk_shutdown_ack,
cf8614
+	[SCTP_CHUNK_TYPE_ERROR]			= &sctp_chunk_error,
cf8614
+	[SCTP_CHUNK_TYPE_COOKIE_ECHO]		= &sctp_chunk_cookie_echo,
cf8614
+	[SCTP_CHUNK_TYPE_COOKIE_ACK]		= &sctp_chunk_cookie_ack,
cf8614
+	[SCTP_CHUNK_TYPE_ECNE]			= &sctp_chunk_ecne,
cf8614
+	[SCTP_CHUNK_TYPE_CWR]			= &sctp_chunk_cwr,
cf8614
+	[SCTP_CHUNK_TYPE_SHUTDOWN_COMPLETE]	= &sctp_chunk_shutdown_complete,
cf8614
+	[SCTP_CHUNK_TYPE_ASCONF_ACK]		= &sctp_chunk_asconf_ack,
cf8614
+	[SCTP_CHUNK_TYPE_FORWARD_TSN]		= &sctp_chunk_forward_tsn,
cf8614
+	[SCTP_CHUNK_TYPE_ASCONF]		= &sctp_chunk_asconf,
cf8614
+};
cf8614
+
cf8614
+const struct exthdr_desc *sctp_chunk_protocol_find(const char *name)
cf8614
+{
cf8614
+	unsigned int i;
cf8614
+
cf8614
+	for (i = 0; i < array_size(sctp_chunk_protocols); i++) {
cf8614
+		if (sctp_chunk_protocols[i] &&
cf8614
+		    !strcmp(sctp_chunk_protocols[i]->name, name))
cf8614
+			return sctp_chunk_protocols[i];
cf8614
+	}
cf8614
+	return NULL;
cf8614
+}
cf8614
+
cf8614
+struct expr *sctp_chunk_expr_alloc(const struct location *loc,
cf8614
+				   unsigned int type, unsigned int field)
cf8614
+{
cf8614
+	const struct proto_hdr_template *tmpl;
cf8614
+	const struct exthdr_desc *desc = NULL;
cf8614
+	struct expr *expr;
cf8614
+
cf8614
+	if (type < array_size(sctp_chunk_protocols))
cf8614
+		desc = sctp_chunk_protocols[type];
cf8614
+
cf8614
+	if (!desc)
cf8614
+		return NULL;
cf8614
+
cf8614
+	tmpl = &desc->templates[field];
cf8614
+	if (!tmpl)
cf8614
+		return NULL;
cf8614
+
cf8614
+	expr = expr_alloc(loc, EXPR_EXTHDR, tmpl->dtype,
cf8614
+			  BYTEORDER_BIG_ENDIAN, tmpl->len);
cf8614
+	expr->exthdr.desc	= desc;
cf8614
+	expr->exthdr.tmpl	= tmpl;
cf8614
+	expr->exthdr.op		= NFT_EXTHDR_OP_SCTP;
cf8614
+	expr->exthdr.raw_type	= desc->type;
cf8614
+	expr->exthdr.offset	= tmpl->offset;
cf8614
+
cf8614
+	return expr;
cf8614
+}
cf8614
+
cf8614
+void sctp_chunk_init_raw(struct expr *expr, uint8_t type, unsigned int off,
cf8614
+			 unsigned int len, uint32_t flags)
cf8614
+{
cf8614
+	const struct proto_hdr_template *tmpl;
cf8614
+	unsigned int i;
cf8614
+
cf8614
+	assert(expr->etype == EXPR_EXTHDR);
cf8614
+
cf8614
+	expr->len = len;
cf8614
+	expr->exthdr.flags = flags;
cf8614
+	expr->exthdr.offset = off;
cf8614
+	expr->exthdr.op = NFT_EXTHDR_OP_SCTP;
cf8614
+
cf8614
+	if (flags & NFT_EXTHDR_F_PRESENT)
cf8614
+		datatype_set(expr, &boolean_type);
cf8614
+	else
cf8614
+		datatype_set(expr, &integer_type);
cf8614
+
cf8614
+	if (type >= array_size(sctp_chunk_protocols))
cf8614
+		return;
cf8614
+
cf8614
+	expr->exthdr.desc = sctp_chunk_protocols[type];
cf8614
+	expr->exthdr.flags = flags;
cf8614
+	assert(expr->exthdr.desc != NULL);
cf8614
+
cf8614
+	for (i = 0; i < array_size(expr->exthdr.desc->templates); ++i) {
cf8614
+		tmpl = &expr->exthdr.desc->templates[i];
cf8614
+		if (tmpl->offset != off || tmpl->len != len)
cf8614
+			continue;
cf8614
+
cf8614
+		if ((flags & NFT_EXTHDR_F_PRESENT) == 0)
cf8614
+			datatype_set(expr, tmpl->dtype);
cf8614
+
cf8614
+		expr->exthdr.tmpl = tmpl;
cf8614
+		break;
cf8614
+	}
cf8614
+}
cf8614
diff --git a/tests/py/inet/sctp.t b/tests/py/inet/sctp.t
cf8614
index 5188b57..3d1c2fd 100644
cf8614
--- a/tests/py/inet/sctp.t
cf8614
+++ b/tests/py/inet/sctp.t
cf8614
@@ -41,3 +41,40 @@ sctp vtag {33, 55, 67, 88};ok
cf8614
 sctp vtag != {33, 55, 67, 88};ok
cf8614
 sctp vtag { 33-55};ok
cf8614
 sctp vtag != { 33-55};ok
cf8614
+
cf8614
+# assert all chunk types are recognized
cf8614
+sctp chunk data exists;ok
cf8614
+sctp chunk init exists;ok
cf8614
+sctp chunk init-ack exists;ok
cf8614
+sctp chunk sack exists;ok
cf8614
+sctp chunk heartbeat exists;ok
cf8614
+sctp chunk heartbeat-ack exists;ok
cf8614
+sctp chunk abort exists;ok
cf8614
+sctp chunk shutdown exists;ok
cf8614
+sctp chunk shutdown-ack exists;ok
cf8614
+sctp chunk error exists;ok
cf8614
+sctp chunk cookie-echo exists;ok
cf8614
+sctp chunk cookie-ack exists;ok
cf8614
+sctp chunk ecne exists;ok
cf8614
+sctp chunk cwr exists;ok
cf8614
+sctp chunk shutdown-complete exists;ok
cf8614
+sctp chunk asconf-ack exists;ok
cf8614
+sctp chunk forward-tsn exists;ok
cf8614
+sctp chunk asconf exists;ok
cf8614
+
cf8614
+# test common header fields in random chunk types
cf8614
+sctp chunk data type 0;ok
cf8614
+sctp chunk init flags 23;ok
cf8614
+sctp chunk init-ack length 42;ok
cf8614
+
cf8614
+# test one custom field in every applicable chunk type
cf8614
+sctp chunk data stream 1337;ok
cf8614
+sctp chunk init initial-tsn 5;ok
cf8614
+sctp chunk init-ack num-outbound-streams 3;ok
cf8614
+sctp chunk sack a-rwnd 1;ok
cf8614
+sctp chunk shutdown cum-tsn-ack 65535;ok
cf8614
+sctp chunk ecne lowest-tsn 5;ok
cf8614
+sctp chunk cwr lowest-tsn 8;ok
cf8614
+sctp chunk asconf-ack seqno 12345;ok
cf8614
+sctp chunk forward-tsn new-cum-tsn 31337;ok
cf8614
+sctp chunk asconf seqno 12345;ok
cf8614
diff --git a/tests/py/inet/sctp.t.json b/tests/py/inet/sctp.t.json
cf8614
index 2684b03..8135686 100644
cf8614
--- a/tests/py/inet/sctp.t.json
cf8614
+++ b/tests/py/inet/sctp.t.json
cf8614
@@ -608,3 +608,481 @@
cf8614
     }
cf8614
 ]
cf8614
 
cf8614
+# sctp chunk data exists
cf8614
+[
cf8614
+    {
cf8614
+        "match": {
cf8614
+            "left": {
cf8614
+                "sctp chunk": {
cf8614
+                    "name": "data"
cf8614
+                }
cf8614
+            },
cf8614
+            "op": "==",
cf8614
+            "right": true
cf8614
+        }
cf8614
+    }
cf8614
+]
cf8614
+
cf8614
+# sctp chunk init exists
cf8614
+[
cf8614
+    {
cf8614
+        "match": {
cf8614
+            "left": {
cf8614
+                "sctp chunk": {
cf8614
+                    "name": "init"
cf8614
+                }
cf8614
+            },
cf8614
+            "op": "==",
cf8614
+            "right": true
cf8614
+        }
cf8614
+    }
cf8614
+]
cf8614
+
cf8614
+# sctp chunk init-ack exists
cf8614
+[
cf8614
+    {
cf8614
+        "match": {
cf8614
+            "left": {
cf8614
+                "sctp chunk": {
cf8614
+                    "name": "init-ack"
cf8614
+                }
cf8614
+            },
cf8614
+            "op": "==",
cf8614
+            "right": true
cf8614
+        }
cf8614
+    }
cf8614
+]
cf8614
+
cf8614
+# sctp chunk sack exists
cf8614
+[
cf8614
+    {
cf8614
+        "match": {
cf8614
+            "left": {
cf8614
+                "sctp chunk": {
cf8614
+                    "name": "sack"
cf8614
+                }
cf8614
+            },
cf8614
+            "op": "==",
cf8614
+            "right": true
cf8614
+        }
cf8614
+    }
cf8614
+]
cf8614
+
cf8614
+# sctp chunk heartbeat exists
cf8614
+[
cf8614
+    {
cf8614
+        "match": {
cf8614
+            "left": {
cf8614
+                "sctp chunk": {
cf8614
+                    "name": "heartbeat"
cf8614
+                }
cf8614
+            },
cf8614
+            "op": "==",
cf8614
+            "right": true
cf8614
+        }
cf8614
+    }
cf8614
+]
cf8614
+
cf8614
+# sctp chunk heartbeat-ack exists
cf8614
+[
cf8614
+    {
cf8614
+        "match": {
cf8614
+            "left": {
cf8614
+                "sctp chunk": {
cf8614
+                    "name": "heartbeat-ack"
cf8614
+                }
cf8614
+            },
cf8614
+            "op": "==",
cf8614
+            "right": true
cf8614
+        }
cf8614
+    }
cf8614
+]
cf8614
+
cf8614
+# sctp chunk abort exists
cf8614
+[
cf8614
+    {
cf8614
+        "match": {
cf8614
+            "left": {
cf8614
+                "sctp chunk": {
cf8614
+                    "name": "abort"
cf8614
+                }
cf8614
+            },
cf8614
+            "op": "==",
cf8614
+            "right": true
cf8614
+        }
cf8614
+    }
cf8614
+]
cf8614
+
cf8614
+# sctp chunk shutdown exists
cf8614
+[
cf8614
+    {
cf8614
+        "match": {
cf8614
+            "left": {
cf8614
+                "sctp chunk": {
cf8614
+                    "name": "shutdown"
cf8614
+                }
cf8614
+            },
cf8614
+            "op": "==",
cf8614
+            "right": true
cf8614
+        }
cf8614
+    }
cf8614
+]
cf8614
+
cf8614
+# sctp chunk shutdown-ack exists
cf8614
+[
cf8614
+    {
cf8614
+        "match": {
cf8614
+            "left": {
cf8614
+                "sctp chunk": {
cf8614
+                    "name": "shutdown-ack"
cf8614
+                }
cf8614
+            },
cf8614
+            "op": "==",
cf8614
+            "right": true
cf8614
+        }
cf8614
+    }
cf8614
+]
cf8614
+
cf8614
+# sctp chunk error exists
cf8614
+[
cf8614
+    {
cf8614
+        "match": {
cf8614
+            "left": {
cf8614
+                "sctp chunk": {
cf8614
+                    "name": "error"
cf8614
+                }
cf8614
+            },
cf8614
+            "op": "==",
cf8614
+            "right": true
cf8614
+        }
cf8614
+    }
cf8614
+]
cf8614
+
cf8614
+# sctp chunk cookie-echo exists
cf8614
+[
cf8614
+    {
cf8614
+        "match": {
cf8614
+            "left": {
cf8614
+                "sctp chunk": {
cf8614
+                    "name": "cookie-echo"
cf8614
+                }
cf8614
+            },
cf8614
+            "op": "==",
cf8614
+            "right": true
cf8614
+        }
cf8614
+    }
cf8614
+]
cf8614
+
cf8614
+# sctp chunk cookie-ack exists
cf8614
+[
cf8614
+    {
cf8614
+        "match": {
cf8614
+            "left": {
cf8614
+                "sctp chunk": {
cf8614
+                    "name": "cookie-ack"
cf8614
+                }
cf8614
+            },
cf8614
+            "op": "==",
cf8614
+            "right": true
cf8614
+        }
cf8614
+    }
cf8614
+]
cf8614
+
cf8614
+# sctp chunk ecne exists
cf8614
+[
cf8614
+    {
cf8614
+        "match": {
cf8614
+            "left": {
cf8614
+                "sctp chunk": {
cf8614
+                    "name": "ecne"
cf8614
+                }
cf8614
+            },
cf8614
+            "op": "==",
cf8614
+            "right": true
cf8614
+        }
cf8614
+    }
cf8614
+]
cf8614
+
cf8614
+# sctp chunk cwr exists
cf8614
+[
cf8614
+    {
cf8614
+        "match": {
cf8614
+            "left": {
cf8614
+                "sctp chunk": {
cf8614
+                    "name": "cwr"
cf8614
+                }
cf8614
+            },
cf8614
+            "op": "==",
cf8614
+            "right": true
cf8614
+        }
cf8614
+    }
cf8614
+]
cf8614
+
cf8614
+# sctp chunk shutdown-complete exists
cf8614
+[
cf8614
+    {
cf8614
+        "match": {
cf8614
+            "left": {
cf8614
+                "sctp chunk": {
cf8614
+                    "name": "shutdown-complete"
cf8614
+                }
cf8614
+            },
cf8614
+            "op": "==",
cf8614
+            "right": true
cf8614
+        }
cf8614
+    }
cf8614
+]
cf8614
+
cf8614
+# sctp chunk asconf-ack exists
cf8614
+[
cf8614
+    {
cf8614
+        "match": {
cf8614
+            "left": {
cf8614
+                "sctp chunk": {
cf8614
+                    "name": "asconf-ack"
cf8614
+                }
cf8614
+            },
cf8614
+            "op": "==",
cf8614
+            "right": true
cf8614
+        }
cf8614
+    }
cf8614
+]
cf8614
+
cf8614
+# sctp chunk forward-tsn exists
cf8614
+[
cf8614
+    {
cf8614
+        "match": {
cf8614
+            "left": {
cf8614
+                "sctp chunk": {
cf8614
+                    "name": "forward-tsn"
cf8614
+                }
cf8614
+            },
cf8614
+            "op": "==",
cf8614
+            "right": true
cf8614
+        }
cf8614
+    }
cf8614
+]
cf8614
+
cf8614
+# sctp chunk asconf exists
cf8614
+[
cf8614
+    {
cf8614
+        "match": {
cf8614
+            "left": {
cf8614
+                "sctp chunk": {
cf8614
+                    "name": "asconf"
cf8614
+                }
cf8614
+            },
cf8614
+            "op": "==",
cf8614
+            "right": true
cf8614
+        }
cf8614
+    }
cf8614
+]
cf8614
+
cf8614
+# sctp chunk data type 0
cf8614
+[
cf8614
+    {
cf8614
+        "match": {
cf8614
+            "left": {
cf8614
+                "sctp chunk": {
cf8614
+                    "field": "type",
cf8614
+                    "name": "data"
cf8614
+                }
cf8614
+            },
cf8614
+            "op": "==",
cf8614
+            "right": 0
cf8614
+        }
cf8614
+    }
cf8614
+]
cf8614
+
cf8614
+# sctp chunk init flags 23
cf8614
+[
cf8614
+    {
cf8614
+        "match": {
cf8614
+            "left": {
cf8614
+                "sctp chunk": {
cf8614
+                    "field": "flags",
cf8614
+                    "name": "init"
cf8614
+                }
cf8614
+            },
cf8614
+            "op": "==",
cf8614
+            "right": 23
cf8614
+        }
cf8614
+    }
cf8614
+]
cf8614
+
cf8614
+# sctp chunk init-ack length 42
cf8614
+[
cf8614
+    {
cf8614
+        "match": {
cf8614
+            "left": {
cf8614
+                "sctp chunk": {
cf8614
+                    "field": "length",
cf8614
+                    "name": "init-ack"
cf8614
+                }
cf8614
+            },
cf8614
+            "op": "==",
cf8614
+            "right": 42
cf8614
+        }
cf8614
+    }
cf8614
+]
cf8614
+
cf8614
+# sctp chunk data stream 1337
cf8614
+[
cf8614
+    {
cf8614
+        "match": {
cf8614
+            "left": {
cf8614
+                "sctp chunk": {
cf8614
+                    "field": "stream",
cf8614
+                    "name": "data"
cf8614
+                }
cf8614
+            },
cf8614
+            "op": "==",
cf8614
+            "right": 1337
cf8614
+        }
cf8614
+    }
cf8614
+]
cf8614
+
cf8614
+# sctp chunk init initial-tsn 5
cf8614
+[
cf8614
+    {
cf8614
+        "match": {
cf8614
+            "left": {
cf8614
+                "sctp chunk": {
cf8614
+                    "field": "initial-tsn",
cf8614
+                    "name": "init"
cf8614
+                }
cf8614
+            },
cf8614
+            "op": "==",
cf8614
+            "right": 5
cf8614
+        }
cf8614
+    }
cf8614
+]
cf8614
+
cf8614
+# sctp chunk init-ack num-outbound-streams 3
cf8614
+[
cf8614
+    {
cf8614
+        "match": {
cf8614
+            "left": {
cf8614
+                "sctp chunk": {
cf8614
+                    "field": "num-outbound-streams",
cf8614
+                    "name": "init-ack"
cf8614
+                }
cf8614
+            },
cf8614
+            "op": "==",
cf8614
+            "right": 3
cf8614
+        }
cf8614
+    }
cf8614
+]
cf8614
+
cf8614
+# sctp chunk sack a-rwnd 1
cf8614
+[
cf8614
+    {
cf8614
+        "match": {
cf8614
+            "left": {
cf8614
+                "sctp chunk": {
cf8614
+                    "field": "a-rwnd",
cf8614
+                    "name": "sack"
cf8614
+                }
cf8614
+            },
cf8614
+            "op": "==",
cf8614
+            "right": 1
cf8614
+        }
cf8614
+    }
cf8614
+]
cf8614
+
cf8614
+# sctp chunk shutdown cum-tsn-ack 65535
cf8614
+[
cf8614
+    {
cf8614
+        "match": {
cf8614
+            "left": {
cf8614
+                "sctp chunk": {
cf8614
+                    "field": "cum-tsn-ack",
cf8614
+                    "name": "shutdown"
cf8614
+                }
cf8614
+            },
cf8614
+            "op": "==",
cf8614
+            "right": 65535
cf8614
+        }
cf8614
+    }
cf8614
+]
cf8614
+
cf8614
+# sctp chunk ecne lowest-tsn 5
cf8614
+[
cf8614
+    {
cf8614
+        "match": {
cf8614
+            "left": {
cf8614
+                "sctp chunk": {
cf8614
+                    "field": "lowest-tsn",
cf8614
+                    "name": "ecne"
cf8614
+                }
cf8614
+            },
cf8614
+            "op": "==",
cf8614
+            "right": 5
cf8614
+        }
cf8614
+    }
cf8614
+]
cf8614
+
cf8614
+# sctp chunk cwr lowest-tsn 8
cf8614
+[
cf8614
+    {
cf8614
+        "match": {
cf8614
+            "left": {
cf8614
+                "sctp chunk": {
cf8614
+                    "field": "lowest-tsn",
cf8614
+                    "name": "cwr"
cf8614
+                }
cf8614
+            },
cf8614
+            "op": "==",
cf8614
+            "right": 8
cf8614
+        }
cf8614
+    }
cf8614
+]
cf8614
+
cf8614
+# sctp chunk asconf-ack seqno 12345
cf8614
+[
cf8614
+    {
cf8614
+        "match": {
cf8614
+            "left": {
cf8614
+                "sctp chunk": {
cf8614
+                    "field": "seqno",
cf8614
+                    "name": "asconf-ack"
cf8614
+                }
cf8614
+            },
cf8614
+            "op": "==",
cf8614
+            "right": 12345
cf8614
+        }
cf8614
+    }
cf8614
+]
cf8614
+
cf8614
+# sctp chunk forward-tsn new-cum-tsn 31337
cf8614
+[
cf8614
+    {
cf8614
+        "match": {
cf8614
+            "left": {
cf8614
+                "sctp chunk": {
cf8614
+                    "field": "new-cum-tsn",
cf8614
+                    "name": "forward-tsn"
cf8614
+                }
cf8614
+            },
cf8614
+            "op": "==",
cf8614
+            "right": 31337
cf8614
+        }
cf8614
+    }
cf8614
+]
cf8614
+
cf8614
+# sctp chunk asconf seqno 12345
cf8614
+[
cf8614
+    {
cf8614
+        "match": {
cf8614
+            "left": {
cf8614
+                "sctp chunk": {
cf8614
+                    "field": "seqno",
cf8614
+                    "name": "asconf"
cf8614
+                }
cf8614
+            },
cf8614
+            "op": "==",
cf8614
+            "right": 12345
cf8614
+        }
cf8614
+    }
cf8614
+]
cf8614
+
cf8614
diff --git a/tests/py/inet/sctp.t.payload b/tests/py/inet/sctp.t.payload
cf8614
index ecfcc72..9c4854c 100644
cf8614
--- a/tests/py/inet/sctp.t.payload
cf8614
+++ b/tests/py/inet/sctp.t.payload
cf8614
@@ -274,3 +274,158 @@ inet test-inet input
cf8614
   [ payload load 4b @ transport header + 4 => reg 1 ]
cf8614
   [ lookup reg 1 set __set%d 0x1 ]
cf8614
 
cf8614
+# sctp chunk data exists
cf8614
+ip
cf8614
+  [ exthdr load 1b @ 0 + 0 present => reg 1 ]
cf8614
+  [ cmp eq reg 1 0x00000001 ]
cf8614
+
cf8614
+# sctp chunk init exists
cf8614
+ip
cf8614
+  [ exthdr load 1b @ 1 + 0 present => reg 1 ]
cf8614
+  [ cmp eq reg 1 0x00000001 ]
cf8614
+
cf8614
+# sctp chunk init-ack exists
cf8614
+ip
cf8614
+  [ exthdr load 1b @ 2 + 0 present => reg 1 ]
cf8614
+  [ cmp eq reg 1 0x00000001 ]
cf8614
+
cf8614
+# sctp chunk sack exists
cf8614
+ip
cf8614
+  [ exthdr load 1b @ 3 + 0 present => reg 1 ]
cf8614
+  [ cmp eq reg 1 0x00000001 ]
cf8614
+
cf8614
+# sctp chunk heartbeat exists
cf8614
+ip
cf8614
+  [ exthdr load 1b @ 4 + 0 present => reg 1 ]
cf8614
+  [ cmp eq reg 1 0x00000001 ]
cf8614
+
cf8614
+# sctp chunk heartbeat-ack exists
cf8614
+ip
cf8614
+  [ exthdr load 1b @ 5 + 0 present => reg 1 ]
cf8614
+  [ cmp eq reg 1 0x00000001 ]
cf8614
+
cf8614
+# sctp chunk abort exists
cf8614
+ip
cf8614
+  [ exthdr load 1b @ 6 + 0 present => reg 1 ]
cf8614
+  [ cmp eq reg 1 0x00000001 ]
cf8614
+
cf8614
+# sctp chunk shutdown exists
cf8614
+ip
cf8614
+  [ exthdr load 1b @ 7 + 0 present => reg 1 ]
cf8614
+  [ cmp eq reg 1 0x00000001 ]
cf8614
+
cf8614
+# sctp chunk shutdown-ack exists
cf8614
+ip
cf8614
+  [ exthdr load 1b @ 8 + 0 present => reg 1 ]
cf8614
+  [ cmp eq reg 1 0x00000001 ]
cf8614
+
cf8614
+# sctp chunk error exists
cf8614
+ip
cf8614
+  [ exthdr load 1b @ 9 + 0 present => reg 1 ]
cf8614
+  [ cmp eq reg 1 0x00000001 ]
cf8614
+
cf8614
+# sctp chunk cookie-echo exists
cf8614
+ip
cf8614
+  [ exthdr load 1b @ 10 + 0 present => reg 1 ]
cf8614
+  [ cmp eq reg 1 0x00000001 ]
cf8614
+
cf8614
+# sctp chunk cookie-ack exists
cf8614
+ip
cf8614
+  [ exthdr load 1b @ 11 + 0 present => reg 1 ]
cf8614
+  [ cmp eq reg 1 0x00000001 ]
cf8614
+
cf8614
+# sctp chunk ecne exists
cf8614
+ip
cf8614
+  [ exthdr load 1b @ 12 + 0 present => reg 1 ]
cf8614
+  [ cmp eq reg 1 0x00000001 ]
cf8614
+
cf8614
+# sctp chunk cwr exists
cf8614
+ip
cf8614
+  [ exthdr load 1b @ 13 + 0 present => reg 1 ]
cf8614
+  [ cmp eq reg 1 0x00000001 ]
cf8614
+
cf8614
+# sctp chunk shutdown-complete exists
cf8614
+ip
cf8614
+  [ exthdr load 1b @ 14 + 0 present => reg 1 ]
cf8614
+  [ cmp eq reg 1 0x00000001 ]
cf8614
+
cf8614
+# sctp chunk asconf-ack exists
cf8614
+ip
cf8614
+  [ exthdr load 1b @ 128 + 0 present => reg 1 ]
cf8614
+  [ cmp eq reg 1 0x00000001 ]
cf8614
+
cf8614
+# sctp chunk forward-tsn exists
cf8614
+ip
cf8614
+  [ exthdr load 1b @ 192 + 0 present => reg 1 ]
cf8614
+  [ cmp eq reg 1 0x00000001 ]
cf8614
+
cf8614
+# sctp chunk asconf exists
cf8614
+ip
cf8614
+  [ exthdr load 1b @ 193 + 0 present => reg 1 ]
cf8614
+  [ cmp eq reg 1 0x00000001 ]
cf8614
+
cf8614
+# sctp chunk data type 0
cf8614
+ip
cf8614
+  [ exthdr load 1b @ 0 + 0 => reg 1 ]
cf8614
+  [ cmp eq reg 1 0x00000000 ]
cf8614
+
cf8614
+# sctp chunk init flags 23
cf8614
+ip
cf8614
+  [ exthdr load 1b @ 1 + 1 => reg 1 ]
cf8614
+  [ cmp eq reg 1 0x00000017 ]
cf8614
+
cf8614
+# sctp chunk init-ack length 42
cf8614
+ip
cf8614
+  [ exthdr load 2b @ 2 + 2 => reg 1 ]
cf8614
+  [ cmp eq reg 1 0x00002a00 ]
cf8614
+
cf8614
+# sctp chunk data stream 1337
cf8614
+ip
cf8614
+  [ exthdr load 2b @ 0 + 8 => reg 1 ]
cf8614
+  [ cmp eq reg 1 0x00003905 ]
cf8614
+
cf8614
+# sctp chunk init initial-tsn 5
cf8614
+ip
cf8614
+  [ exthdr load 4b @ 1 + 16 => reg 1 ]
cf8614
+  [ cmp eq reg 1 0x05000000 ]
cf8614
+
cf8614
+# sctp chunk init-ack num-outbound-streams 3
cf8614
+ip
cf8614
+  [ exthdr load 2b @ 2 + 12 => reg 1 ]
cf8614
+  [ cmp eq reg 1 0x00000300 ]
cf8614
+
cf8614
+# sctp chunk sack a-rwnd 1
cf8614
+ip
cf8614
+  [ exthdr load 4b @ 3 + 8 => reg 1 ]
cf8614
+  [ cmp eq reg 1 0x01000000 ]
cf8614
+
cf8614
+# sctp chunk shutdown cum-tsn-ack 65535
cf8614
+ip
cf8614
+  [ exthdr load 4b @ 7 + 4 => reg 1 ]
cf8614
+  [ cmp eq reg 1 0xffff0000 ]
cf8614
+
cf8614
+# sctp chunk ecne lowest-tsn 5
cf8614
+ip
cf8614
+  [ exthdr load 4b @ 12 + 4 => reg 1 ]
cf8614
+  [ cmp eq reg 1 0x05000000 ]
cf8614
+
cf8614
+# sctp chunk cwr lowest-tsn 8
cf8614
+ip
cf8614
+  [ exthdr load 4b @ 13 + 4 => reg 1 ]
cf8614
+  [ cmp eq reg 1 0x08000000 ]
cf8614
+
cf8614
+# sctp chunk asconf-ack seqno 12345
cf8614
+ip
cf8614
+  [ exthdr load 4b @ 128 + 4 => reg 1 ]
cf8614
+  [ cmp eq reg 1 0x39300000 ]
cf8614
+
cf8614
+# sctp chunk forward-tsn new-cum-tsn 31337
cf8614
+ip
cf8614
+  [ exthdr load 4b @ 192 + 4 => reg 1 ]
cf8614
+  [ cmp eq reg 1 0x697a0000 ]
cf8614
+
cf8614
+# sctp chunk asconf seqno 12345
cf8614
+ip
cf8614
+  [ exthdr load 4b @ 193 + 4 => reg 1 ]
cf8614
+  [ cmp eq reg 1 0x39300000 ]
cf8614
+
cf8614
-- 
cf8614
2.31.1
cf8614