|
|
87db66 |
From 98794894774a39927bc975921fc9e40f00db937b Mon Sep 17 00:00:00 2001
|
|
|
87db66 |
From: Phil Sutter <phil@nwl.cc>
|
|
|
87db66 |
Date: Wed, 2 Dec 2020 13:37:06 +0100
|
|
|
87db66 |
Subject: [PATCH] extensions: dccp: Fix for DCCP type 'INVALID'
|
|
|
87db66 |
|
|
|
87db66 |
Support for matching on invalid DCCP type field values was pretty
|
|
|
87db66 |
broken: While RFC4340 declares any type value from 10 to 15 invalid, the
|
|
|
87db66 |
extension's type name 'INVALID' mapped to type value 10 only. Fix this
|
|
|
87db66 |
by introduction of INVALID_OTHER_TYPE_MASK which has the remaining
|
|
|
87db66 |
invalid type's bits set and apply it if bit 10 is set after parsing the
|
|
|
87db66 |
type list. When printing, stop searching type names after printing
|
|
|
87db66 |
'INVALID' - unless numeric output was requested. The latter prints all
|
|
|
87db66 |
actual type values. Since parsing types in numeric form is not
|
|
|
87db66 |
supported, changing the output should not break existing scripts.
|
|
|
87db66 |
|
|
|
87db66 |
When translating into nftables syntax, the code returned prematurely if
|
|
|
87db66 |
'INVALID' was among the list of types - thereby emitting invalid syntax.
|
|
|
87db66 |
Instead print a real match for invalid types by use of a range
|
|
|
87db66 |
expression.
|
|
|
87db66 |
|
|
|
87db66 |
While being at it, fix syntax of translator output: If only
|
|
|
87db66 |
'--dccp-types' was translated, the output contained an extra 'dccp'. On
|
|
|
87db66 |
the other hand, if '--sport' and '--dport' was present, a required
|
|
|
87db66 |
'dccp' between the translations of both was missing.
|
|
|
87db66 |
|
|
|
87db66 |
Fixes: e40b11d7ef827 ("add support for new 'dccp' protocol match")
|
|
|
87db66 |
Fixes: c94a998724143 ("extensions: libxt_dccp: Add translation to nft")
|
|
|
87db66 |
Signed-off-by: Phil Sutter <phil@nwl.cc>
|
|
|
87db66 |
(cherry picked from commit 4bcbc8e11a2764f4537dc405962f83cd072cccfe)
|
|
|
87db66 |
Signed-off-by: Phil Sutter <psutter@redhat.com>
|
|
|
87db66 |
---
|
|
|
87db66 |
extensions/libxt_dccp.c | 58 ++++++++++++++++++++++--------------
|
|
|
87db66 |
extensions/libxt_dccp.txlate | 12 ++++++--
|
|
|
87db66 |
2 files changed, 45 insertions(+), 25 deletions(-)
|
|
|
87db66 |
|
|
|
87db66 |
diff --git a/extensions/libxt_dccp.c b/extensions/libxt_dccp.c
|
|
|
87db66 |
index 5e67c264db2a9..aea3e20be4818 100644
|
|
|
87db66 |
--- a/extensions/libxt_dccp.c
|
|
|
87db66 |
+++ b/extensions/libxt_dccp.c
|
|
|
87db66 |
@@ -76,6 +76,9 @@ static const char *const dccp_pkt_types[] = {
|
|
|
87db66 |
[DCCP_PKT_INVALID] = "INVALID",
|
|
|
87db66 |
};
|
|
|
87db66 |
|
|
|
87db66 |
+/* Bits for type values 11-15 */
|
|
|
87db66 |
+#define INVALID_OTHER_TYPE_MASK 0xf800
|
|
|
87db66 |
+
|
|
|
87db66 |
static uint16_t
|
|
|
87db66 |
parse_dccp_types(const char *typestring)
|
|
|
87db66 |
{
|
|
|
87db66 |
@@ -95,6 +98,9 @@ parse_dccp_types(const char *typestring)
|
|
|
87db66 |
xtables_error(PARAMETER_PROBLEM,
|
|
|
87db66 |
"Unknown DCCP type `%s'", ptr);
|
|
|
87db66 |
}
|
|
|
87db66 |
+ if (typemask & (1 << DCCP_PKT_INVALID))
|
|
|
87db66 |
+ typemask |= INVALID_OTHER_TYPE_MASK;
|
|
|
87db66 |
+
|
|
|
87db66 |
|
|
|
87db66 |
free(buffer);
|
|
|
87db66 |
return typemask;
|
|
|
87db66 |
@@ -193,9 +199,13 @@ print_types(uint16_t types, int inverted, int numeric)
|
|
|
87db66 |
|
|
|
87db66 |
if (numeric)
|
|
|
87db66 |
printf("%u", i);
|
|
|
87db66 |
- else
|
|
|
87db66 |
+ else {
|
|
|
87db66 |
printf("%s", dccp_pkt_types[i]);
|
|
|
87db66 |
|
|
|
87db66 |
+ if (i == DCCP_PKT_INVALID)
|
|
|
87db66 |
+ break;
|
|
|
87db66 |
+ }
|
|
|
87db66 |
+
|
|
|
87db66 |
types &= ~(1 << i);
|
|
|
87db66 |
}
|
|
|
87db66 |
}
|
|
|
87db66 |
@@ -288,6 +298,7 @@ static const char *const dccp_pkt_types_xlate[] = {
|
|
|
87db66 |
[DCCP_PKT_RESET] = "reset",
|
|
|
87db66 |
[DCCP_PKT_SYNC] = "sync",
|
|
|
87db66 |
[DCCP_PKT_SYNCACK] = "syncack",
|
|
|
87db66 |
+ [DCCP_PKT_INVALID] = "10-15",
|
|
|
87db66 |
};
|
|
|
87db66 |
|
|
|
87db66 |
static int dccp_type_xlate(const struct xt_dccp_info *einfo,
|
|
|
87db66 |
@@ -296,10 +307,10 @@ static int dccp_type_xlate(const struct xt_dccp_info *einfo,
|
|
|
87db66 |
bool have_type = false, set_need = false;
|
|
|
87db66 |
uint16_t types = einfo->typemask;
|
|
|
87db66 |
|
|
|
87db66 |
- if (types & (1 << DCCP_PKT_INVALID))
|
|
|
87db66 |
- return 0;
|
|
|
87db66 |
-
|
|
|
87db66 |
- xt_xlate_add(xl, " dccp type%s ", einfo->invflags ? " !=" : "");
|
|
|
87db66 |
+ if (types & INVALID_OTHER_TYPE_MASK) {
|
|
|
87db66 |
+ types &= ~INVALID_OTHER_TYPE_MASK;
|
|
|
87db66 |
+ types |= 1 << DCCP_PKT_INVALID;
|
|
|
87db66 |
+ }
|
|
|
87db66 |
|
|
|
87db66 |
if ((types != 0) && !(types == (types & -types))) {
|
|
|
87db66 |
xt_xlate_add(xl, "{");
|
|
|
87db66 |
@@ -335,34 +346,37 @@ static int dccp_xlate(struct xt_xlate *xl,
|
|
|
87db66 |
char *space = "";
|
|
|
87db66 |
int ret = 1;
|
|
|
87db66 |
|
|
|
87db66 |
- xt_xlate_add(xl, "dccp ");
|
|
|
87db66 |
-
|
|
|
87db66 |
if (einfo->flags & XT_DCCP_SRC_PORTS) {
|
|
|
87db66 |
+ xt_xlate_add(xl, "dccp sport%s %u",
|
|
|
87db66 |
+ einfo->invflags & XT_DCCP_SRC_PORTS ? " !=" : "",
|
|
|
87db66 |
+ einfo->spts[0]);
|
|
|
87db66 |
+
|
|
|
87db66 |
if (einfo->spts[0] != einfo->spts[1])
|
|
|
87db66 |
- xt_xlate_add(xl, "sport%s %u-%u",
|
|
|
87db66 |
- einfo->invflags & XT_DCCP_SRC_PORTS ? " !=" : "",
|
|
|
87db66 |
- einfo->spts[0], einfo->spts[1]);
|
|
|
87db66 |
- else
|
|
|
87db66 |
- xt_xlate_add(xl, "sport%s %u",
|
|
|
87db66 |
- einfo->invflags & XT_DCCP_SRC_PORTS ? " !=" : "",
|
|
|
87db66 |
- einfo->spts[0]);
|
|
|
87db66 |
+ xt_xlate_add(xl, "-%u", einfo->spts[1]);
|
|
|
87db66 |
+
|
|
|
87db66 |
space = " ";
|
|
|
87db66 |
}
|
|
|
87db66 |
|
|
|
87db66 |
if (einfo->flags & XT_DCCP_DEST_PORTS) {
|
|
|
87db66 |
+ xt_xlate_add(xl, "%sdccp dport%s %u", space,
|
|
|
87db66 |
+ einfo->invflags & XT_DCCP_DEST_PORTS ? " !=" : "",
|
|
|
87db66 |
+ einfo->dpts[0]);
|
|
|
87db66 |
+
|
|
|
87db66 |
if (einfo->dpts[0] != einfo->dpts[1])
|
|
|
87db66 |
- xt_xlate_add(xl, "%sdport%s %u-%u", space,
|
|
|
87db66 |
- einfo->invflags & XT_DCCP_DEST_PORTS ? " !=" : "",
|
|
|
87db66 |
- einfo->dpts[0], einfo->dpts[1]);
|
|
|
87db66 |
- else
|
|
|
87db66 |
- xt_xlate_add(xl, "%sdport%s %u", space,
|
|
|
87db66 |
- einfo->invflags & XT_DCCP_DEST_PORTS ? " !=" : "",
|
|
|
87db66 |
- einfo->dpts[0]);
|
|
|
87db66 |
+ xt_xlate_add(xl, "-%u", einfo->dpts[1]);
|
|
|
87db66 |
+
|
|
|
87db66 |
+ space = " ";
|
|
|
87db66 |
}
|
|
|
87db66 |
|
|
|
87db66 |
- if (einfo->flags & XT_DCCP_TYPE)
|
|
|
87db66 |
+ if (einfo->flags & XT_DCCP_TYPE && einfo->typemask) {
|
|
|
87db66 |
+ xt_xlate_add(xl, "%sdccp type%s ", space,
|
|
|
87db66 |
+ einfo->invflags & XT_DCCP_TYPE ? " !=" : "");
|
|
|
87db66 |
ret = dccp_type_xlate(einfo, xl);
|
|
|
87db66 |
|
|
|
87db66 |
+ space = " ";
|
|
|
87db66 |
+ }
|
|
|
87db66 |
+
|
|
|
87db66 |
+ /* FIXME: no dccp option support in nftables yet */
|
|
|
87db66 |
if (einfo->flags & XT_DCCP_OPTION)
|
|
|
87db66 |
ret = 0;
|
|
|
87db66 |
|
|
|
87db66 |
diff --git a/extensions/libxt_dccp.txlate b/extensions/libxt_dccp.txlate
|
|
|
87db66 |
index b47dc65f5bc4f..ea853f6acf627 100644
|
|
|
87db66 |
--- a/extensions/libxt_dccp.txlate
|
|
|
87db66 |
+++ b/extensions/libxt_dccp.txlate
|
|
|
87db66 |
@@ -7,8 +7,14 @@ nft add rule ip filter INPUT dccp dport 100-200 counter
|
|
|
87db66 |
iptables-translate -A INPUT -p dccp -m dccp ! --dport 100
|
|
|
87db66 |
nft add rule ip filter INPUT dccp dport != 100 counter
|
|
|
87db66 |
|
|
|
87db66 |
-iptables-translate -A INPUT -p dccp -m dccp --dport 100 --dccp-types REQUEST,RESPONSE,DATA,ACK,DATAACK,CLOSEREQ,CLOSE,SYNC,SYNCACK
|
|
|
87db66 |
-nft add rule ip filter INPUT dccp dport 100 dccp type {request, response, data, ack, dataack, closereq, close, sync, syncack} counter
|
|
|
87db66 |
+iptables-translate -A INPUT -p dccp -m dccp --dccp-types CLOSE
|
|
|
87db66 |
+nft add rule ip filter INPUT dccp type close counter
|
|
|
87db66 |
+
|
|
|
87db66 |
+iptables-translate -A INPUT -p dccp -m dccp --dccp-types INVALID
|
|
|
87db66 |
+nft add rule ip filter INPUT dccp type 10-15 counter
|
|
|
87db66 |
+
|
|
|
87db66 |
+iptables-translate -A INPUT -p dccp -m dccp --dport 100 --dccp-types REQUEST,RESPONSE,DATA,ACK,DATAACK,CLOSEREQ,CLOSE,SYNC,SYNCACK,INVALID
|
|
|
87db66 |
+nft add rule ip filter INPUT dccp dport 100 dccp type {request, response, data, ack, dataack, closereq, close, sync, syncack, 10-15} counter
|
|
|
87db66 |
|
|
|
87db66 |
iptables-translate -A INPUT -p dccp -m dccp --sport 200 --dport 100
|
|
|
87db66 |
-nft add rule ip filter INPUT dccp sport 200 dport 100 counter
|
|
|
87db66 |
+nft add rule ip filter INPUT dccp sport 200 dccp dport 100 counter
|
|
|
87db66 |
--
|
|
|
87db66 |
2.28.0
|
|
|
87db66 |
|