Attention is currently required from: fixeria.
neels has posted comments on this change. ( https://gerrit.osmocom.org/c/libosmo-pfcp/+/30406 )
Change subject: fix coding of Network Instance IE
......................................................................
Patch Set 1:
(1 comment)
Patchset:
PS1:
I wasn't aware / looked but didn't find the apn.c ones. They should work.
BTW, i had found another implementation in osmo-hlr.git and they didn't fit so well with the msgb target, using avoidable dynamic allocation:
osmo_mdns_rfc_qname_encode()
osmo_mdns_rfc_qname_decode()
maybe we should also replace those with the apn.c implementations
--
To view, visit https://gerrit.osmocom.org/c/libosmo-pfcp/+/30406
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: libosmo-pfcp
Gerrit-Branch: master
Gerrit-Change-Id: I9d67464ef0f92b0512cfd6e48d203f8828a82a19
Gerrit-Change-Number: 30406
Gerrit-PatchSet: 1
Gerrit-Owner: neels <nhofmeyr(a)sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-CC: pespin <pespin(a)sysmocom.de>
Gerrit-Attention: fixeria <vyanitskiy(a)sysmocom.de>
Gerrit-Comment-Date: Thu, 08 Dec 2022 00:35:18 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Gerrit-MessageType: comment
neels has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-upf/+/30499 )
Change subject: vty: add: show nft-rule tunmap example
......................................................................
vty: add: show nft-rule tunmap example
Add VTY command to print out an nftables ruleset that osmo-upf produces,
with arbitrary IP addrs / TEIDs inserted. This allows tracking in *.vty
tests how the nftables rulesets are changed by patches.
future:
- Adding the 'tunmap' keyword to allow adding show commands for
different uses of nftables.
- Adding the 'example' keyword to allow adding show commands for
actual tunmap IDs / PFCP session IDs / ...
- Matches upcoming vty commands
'nft-rule tunmap append .NFT_RULE'
'no nft-rule tunmap append'
'show nft-rule tunmap append'
Add new separate nft-rule.vty -- more to come here in upcoming patch.
Change-Id: I9b57aa492c051e480c9bd819ae58f8f59a13af40
---
M src/osmo-upf/upf_nft.c
M src/osmo-upf/upf_vty.c
A tests/nft-rule.vty
M tests/upf.vty
4 files changed, 65 insertions(+), 3 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/osmo-upf refs/changes/99/30499/1
diff --git a/src/osmo-upf/upf_nft.c b/src/osmo-upf/upf_nft.c
index afc2fac..a0f005d 100644
--- a/src/osmo-upf/upf_nft.c
+++ b/src/osmo-upf/upf_nft.c
@@ -64,6 +64,12 @@
int upf_nft_init()
{
int rc;
+
+ /* Always set up the default settings, also in mockup mode, so that the VTY reflects sane values */
+ if (!g_upf->nft.table_name)
+ g_upf->nft.table_name = talloc_strdup(g_upf, "osmo-upf");
+
+ /* When in mockup mode, do not set up nft_ctx and netfilter table */
if (g_upf->nft.mockup) {
LOGP(DNFT, LOGL_NOTICE,
"tunmap/mockup active: not allocating libnftables nft_ctx. FOR TESTING PURPOSES ONLY.\n");
@@ -76,9 +82,6 @@
return -EIO;
}
- if (!g_upf->nft.table_name)
- g_upf->nft.table_name = talloc_strdup(g_upf, "osmo-upf");
-
rc = upf_nft_run(upf_nft_ruleset_table_create(OTC_SELECT, g_upf->nft.table_name));
if (rc) {
LOGP(DNFT, LOGL_ERROR, "Failed to create nft table %s\n",
diff --git a/src/osmo-upf/upf_vty.c b/src/osmo-upf/upf_vty.c
index aff7590..6d74b21 100644
--- a/src/osmo-upf/upf_vty.c
+++ b/src/osmo-upf/upf_vty.c
@@ -254,6 +254,43 @@
return CMD_SUCCESS;
}
+#define NFT_RULE_STR "nftables rule specifics\n"
+#define TUNMAP_STR "GTP tunmap use case (a.k.a. forwarding between two GTP tunnels)\n"
+
+DEFUN(show_nft_rule_tunmap_example, show_nft_rule_tunmap_example_cmd,
+ "show nft-rule tunmap example",
+ SHOW_STR NFT_RULE_STR TUNMAP_STR
+ "Print a complete nftables ruleset for a tunmap filled with example IP addresses and TEIDs\n")
+{
+ struct osmo_sockaddr_str str = {};
+ struct upf_nft_tunmap_desc d = {
+ .access = {
+ .local_teid = 0x201,
+ .remote_teid = 0x102,
+ },
+ .core = {
+ .local_teid = 0x203,
+ .remote_teid = 0x302,
+ },
+ .id = 123,
+ };
+
+ osmo_sockaddr_str_from_str2(&str, "1.1.1.1");
+ osmo_sockaddr_str_to_sockaddr(&str, &d.access.gtp_remote_addr.u.sas);
+
+ osmo_sockaddr_str_from_str2(&str, "2.2.2.1");
+ osmo_sockaddr_str_to_sockaddr(&str, &d.access.gtp_local_addr.u.sas);
+
+ osmo_sockaddr_str_from_str2(&str, "2.2.2.3");
+ osmo_sockaddr_str_to_sockaddr(&str, &d.core.gtp_local_addr.u.sas);
+
+ osmo_sockaddr_str_from_str2(&str, "3.3.3.3");
+ osmo_sockaddr_str_to_sockaddr(&str, &d.core.gtp_remote_addr.u.sas);
+
+ vty_out(vty, "%s%s", upf_nft_tunmap_get_ruleset_str(OTC_SELECT, &d), VTY_NEWLINE);
+ return CMD_SUCCESS;
+}
+
static struct cmd_node cfg_netinst_node = {
NETINST_NODE,
"%s(config-netinst)# ",
@@ -435,6 +472,7 @@
install_element(TUNMAP_NODE, &cfg_tunmap_mockup_cmd);
install_element(TUNMAP_NODE, &cfg_tunmap_no_mockup_cmd);
install_element(TUNMAP_NODE, &cfg_tunmap_table_name_cmd);
+ install_element(TUNMAP_NODE, &show_nft_rule_tunmap_example_cmd);
install_node(&cfg_netinst_node, config_write_netinst);
install_element(CONFIG_NODE, &cfg_netinst_cmd);
diff --git a/tests/nft-rule.vty b/tests/nft-rule.vty
new file mode 100644
index 0000000..f328871
--- /dev/null
+++ b/tests/nft-rule.vty
@@ -0,0 +1,8 @@
+OsmoUPF> enable
+OsmoUPF# configure terminal
+OsmoUPF(config)# tunmap
+
+OsmoUPF(config-tunmap)# show nft-rule tunmap example
+add chain inet osmo-upf tunmap123 { type filter hook prerouting priority -300; }
+add rule inet osmo-upf tunmap123 meta l4proto udp ip daddr 2.2.2.1 @ih,32,32 0x00000201 ip saddr set 2.2.2.3 ip daddr set 3.3.3.3 @ih,32,32 set 0x00000302 counter;
+add rule inet osmo-upf tunmap123 meta l4proto udp ip daddr 2.2.2.3 @ih,32,32 0x00000203 ip saddr set 2.2.2.1 ip daddr set 1.1.1.1 @ih,32,32 set 0x00000102 counter;
diff --git a/tests/upf.vty b/tests/upf.vty
index 5100b17..8931719 100644
--- a/tests/upf.vty
+++ b/tests/upf.vty
@@ -52,6 +52,7 @@
mockup
no mockup
table-name TABLE_NAME
+ show nft-rule tunmap example
OsmoUPF(config-tunmap)# exit
OsmoUPF(config)# tunmap
@@ -60,6 +61,7 @@
mockup
no mockup
table-name TABLE_NAME
+ show nft-rule tunmap example
OsmoUPF(config-tunmap)# mockup?
mockup don't actually send rulesets to nftables, just return success
@@ -70,3 +72,14 @@
table-name Set the nft inet table name to create and place GTP tunnel forwarding chains in (as in 'nft add table inet foo'). If multiple instances of osmo-upf are running on the same system, each osmo-upf must have its own table name. Otherwise the names of created forwarding chains will collide. The default table name is "osmo-upf".
OsmoUPF(config-tunmap)# table-name ?
TABLE_NAME nft inet table name
+
+OsmoUPF(config-tunmap)# show?
+ show Show running system information
+OsmoUPF(config-tunmap)# show ?
+...
+ nft-rule nftables rule specifics
+...
+OsmoUPF(config-tunmap)# show nft-rule ?
+ tunmap GTP tunmap use case (a.k.a. forwarding between two GTP tunnels)
+OsmoUPF(config-tunmap)# show nft-rule tunmap ?
+ example Print a complete nftables ruleset for a tunmap filled with example IP addresses and TEIDs
--
To view, visit https://gerrit.osmocom.org/c/osmo-upf/+/30499
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: osmo-upf
Gerrit-Branch: master
Gerrit-Change-Id: I9b57aa492c051e480c9bd819ae58f8f59a13af40
Gerrit-Change-Number: 30499
Gerrit-PatchSet: 1
Gerrit-Owner: neels <nhofmeyr(a)sysmocom.de>
Gerrit-MessageType: newchange
neels has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-upf/+/30501 )
Change subject: nft: append 'accept' to each rule
......................................................................
nft: append 'accept' to each rule
This 'accept' is not an optional addition, it should always be present.
(Just saying because previous patch added a VTY command to configure
additions to the rules, and this patch is orthogonal to that.)
Related: OS#5810
Change-Id: I129133cc5d7180ce3761d5604d602d23a5ef9825
---
M src/osmo-upf/upf_nft.c
M tests/nft-rule.vty
2 files changed, 11 insertions(+), 10 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/osmo-upf refs/changes/01/30501/1
diff --git a/src/osmo-upf/upf_nft.c b/src/osmo-upf/upf_nft.c
index bf5d2c7..54ba32f 100644
--- a/src/osmo-upf/upf_nft.c
+++ b/src/osmo-upf/upf_nft.c
@@ -162,6 +162,7 @@
OSMO_STRBUF_PRINTF(sb, " %s", i->str);
}
+ OSMO_STRBUF_PRINTF(sb, " accept");
OSMO_STRBUF_PRINTF(sb, ";\n");
return sb.chars_needed;
diff --git a/tests/nft-rule.vty b/tests/nft-rule.vty
index 7e8952b..c52ef0e 100644
--- a/tests/nft-rule.vty
+++ b/tests/nft-rule.vty
@@ -6,16 +6,16 @@
no nft-rule tunmap append
OsmoUPF(config-tunmap)# show nft-rule tunmap example
add chain inet osmo-upf tunmap123 { type filter hook prerouting priority -300; }
-add rule inet osmo-upf tunmap123 meta l4proto udp ip daddr 2.2.2.1 @ih,32,32 0x00000201 ip saddr set 2.2.2.3 ip daddr set 3.3.3.3 @ih,32,32 set 0x00000302 counter;
-add rule inet osmo-upf tunmap123 meta l4proto udp ip daddr 2.2.2.3 @ih,32,32 0x00000203 ip saddr set 2.2.2.1 ip daddr set 1.1.1.1 @ih,32,32 set 0x00000102 counter;
+add rule inet osmo-upf tunmap123 meta l4proto udp ip daddr 2.2.2.1 @ih,32,32 0x00000201 ip saddr set 2.2.2.3 ip daddr set 3.3.3.3 @ih,32,32 set 0x00000302 counter accept;
+add rule inet osmo-upf tunmap123 meta l4proto udp ip daddr 2.2.2.3 @ih,32,32 0x00000203 ip saddr set 2.2.2.1 ip daddr set 1.1.1.1 @ih,32,32 set 0x00000102 counter accept;
OsmoUPF(config-tunmap)# nft-rule tunmap append meta nftrace set 1
OsmoUPF(config-tunmap)# show nft-rule tunmap append
nft-rule tunmap append meta nftrace set 1
OsmoUPF(config-tunmap)# show nft-rule tunmap example
add chain inet osmo-upf tunmap123 { type filter hook prerouting priority -300; }
-add rule inet osmo-upf tunmap123 meta l4proto udp ip daddr 2.2.2.1 @ih,32,32 0x00000201 ip saddr set 2.2.2.3 ip daddr set 3.3.3.3 @ih,32,32 set 0x00000302 counter meta nftrace set 1;
-add rule inet osmo-upf tunmap123 meta l4proto udp ip daddr 2.2.2.3 @ih,32,32 0x00000203 ip saddr set 2.2.2.1 ip daddr set 1.1.1.1 @ih,32,32 set 0x00000102 counter meta nftrace set 1;
+add rule inet osmo-upf tunmap123 meta l4proto udp ip daddr 2.2.2.1 @ih,32,32 0x00000201 ip saddr set 2.2.2.3 ip daddr set 3.3.3.3 @ih,32,32 set 0x00000302 counter meta nftrace set 1 accept;
+add rule inet osmo-upf tunmap123 meta l4proto udp ip daddr 2.2.2.3 @ih,32,32 0x00000203 ip saddr set 2.2.2.1 ip daddr set 1.1.1.1 @ih,32,32 set 0x00000102 counter meta nftrace set 1 accept;
OsmoUPF(config-tunmap)# nft-rule tunmap append foo
OsmoUPF(config-tunmap)# show nft-rule tunmap append
@@ -23,8 +23,8 @@
nft-rule tunmap append foo
OsmoUPF(config-tunmap)# show nft-rule tunmap example
add chain inet osmo-upf tunmap123 { type filter hook prerouting priority -300; }
-add rule inet osmo-upf tunmap123 meta l4proto udp ip daddr 2.2.2.1 @ih,32,32 0x00000201 ip saddr set 2.2.2.3 ip daddr set 3.3.3.3 @ih,32,32 set 0x00000302 counter meta nftrace set 1 foo;
-add rule inet osmo-upf tunmap123 meta l4proto udp ip daddr 2.2.2.3 @ih,32,32 0x00000203 ip saddr set 2.2.2.1 ip daddr set 1.1.1.1 @ih,32,32 set 0x00000102 counter meta nftrace set 1 foo;
+add rule inet osmo-upf tunmap123 meta l4proto udp ip daddr 2.2.2.1 @ih,32,32 0x00000201 ip saddr set 2.2.2.3 ip daddr set 3.3.3.3 @ih,32,32 set 0x00000302 counter meta nftrace set 1 foo accept;
+add rule inet osmo-upf tunmap123 meta l4proto udp ip daddr 2.2.2.3 @ih,32,32 0x00000203 ip saddr set 2.2.2.1 ip daddr set 1.1.1.1 @ih,32,32 set 0x00000102 counter meta nftrace set 1 foo accept;
OsmoUPF(config-tunmap)# nft-rule tunmap append bar
OsmoUPF(config-tunmap)# show nft-rule tunmap append
@@ -33,8 +33,8 @@
nft-rule tunmap append bar
OsmoUPF(config-tunmap)# show nft-rule tunmap example
add chain inet osmo-upf tunmap123 { type filter hook prerouting priority -300; }
-add rule inet osmo-upf tunmap123 meta l4proto udp ip daddr 2.2.2.1 @ih,32,32 0x00000201 ip saddr set 2.2.2.3 ip daddr set 3.3.3.3 @ih,32,32 set 0x00000302 counter meta nftrace set 1 foo bar;
-add rule inet osmo-upf tunmap123 meta l4proto udp ip daddr 2.2.2.3 @ih,32,32 0x00000203 ip saddr set 2.2.2.1 ip daddr set 1.1.1.1 @ih,32,32 set 0x00000102 counter meta nftrace set 1 foo bar;
+add rule inet osmo-upf tunmap123 meta l4proto udp ip daddr 2.2.2.1 @ih,32,32 0x00000201 ip saddr set 2.2.2.3 ip daddr set 3.3.3.3 @ih,32,32 set 0x00000302 counter meta nftrace set 1 foo bar accept;
+add rule inet osmo-upf tunmap123 meta l4proto udp ip daddr 2.2.2.3 @ih,32,32 0x00000203 ip saddr set 2.2.2.1 ip daddr set 1.1.1.1 @ih,32,32 set 0x00000102 counter meta nftrace set 1 foo bar accept;
OsmoUPF(config-tunmap)# show running-config
...
@@ -50,5 +50,5 @@
no nft-rule tunmap append
OsmoUPF(config-tunmap)# show nft-rule tunmap example
add chain inet osmo-upf tunmap123 { type filter hook prerouting priority -300; }
-add rule inet osmo-upf tunmap123 meta l4proto udp ip daddr 2.2.2.1 @ih,32,32 0x00000201 ip saddr set 2.2.2.3 ip daddr set 3.3.3.3 @ih,32,32 set 0x00000302 counter;
-add rule inet osmo-upf tunmap123 meta l4proto udp ip daddr 2.2.2.3 @ih,32,32 0x00000203 ip saddr set 2.2.2.1 ip daddr set 1.1.1.1 @ih,32,32 set 0x00000102 counter;
+add rule inet osmo-upf tunmap123 meta l4proto udp ip daddr 2.2.2.1 @ih,32,32 0x00000201 ip saddr set 2.2.2.3 ip daddr set 3.3.3.3 @ih,32,32 set 0x00000302 counter accept;
+add rule inet osmo-upf tunmap123 meta l4proto udp ip daddr 2.2.2.3 @ih,32,32 0x00000203 ip saddr set 2.2.2.1 ip daddr set 1.1.1.1 @ih,32,32 set 0x00000102 counter accept;
--
To view, visit https://gerrit.osmocom.org/c/osmo-upf/+/30501
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: osmo-upf
Gerrit-Branch: master
Gerrit-Change-Id: I129133cc5d7180ce3761d5604d602d23a5ef9825
Gerrit-Change-Number: 30501
Gerrit-PatchSet: 1
Gerrit-Owner: neels <nhofmeyr(a)sysmocom.de>
Gerrit-MessageType: newchange
neels has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-upf/+/30493 )
Change subject: nft: rewrite source IP in outgoing GTP-U
......................................................................
nft: rewrite source IP in outgoing GTP-U
Change-Id: I6d293c1dc69d1bab714564f48e3f85b769501d13
---
M src/osmo-upf/upf_nft.c
1 file changed, 4 insertions(+), 0 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/osmo-upf refs/changes/93/30493/1
diff --git a/src/osmo-upf/upf_nft.c b/src/osmo-upf/upf_nft.c
index 695ec20..a8ca90d 100644
--- a/src/osmo-upf/upf_nft.c
+++ b/src/osmo-upf/upf_nft.c
@@ -136,6 +136,10 @@
/* Match on the TEID in the header */
OSMO_STRBUF_PRINTF(sb, " @ih,32,32 0x%08x", from_peer->teid_local);
+ /* Change outgoing address to local IP on outgoing interface */
+ OSMO_STRBUF_PRINTF(sb, " ip saddr set ");
+ OSMO_STRBUF_APPEND(sb, osmo_sockaddr_to_str_buf2, to_peer->addr_local);
+
/* Change destination address to to_peer */
OSMO_STRBUF_PRINTF(sb, " ip daddr set ");
OSMO_STRBUF_APPEND(sb, osmo_sockaddr_to_str_buf2, to_peer->addr_remote);
--
To view, visit https://gerrit.osmocom.org/c/osmo-upf/+/30493
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: osmo-upf
Gerrit-Branch: master
Gerrit-Change-Id: I6d293c1dc69d1bab714564f48e3f85b769501d13
Gerrit-Change-Number: 30493
Gerrit-PatchSet: 1
Gerrit-Owner: neels <nhofmeyr(a)sysmocom.de>
Gerrit-MessageType: newchange
neels has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-upf/+/30492 )
Change subject: nft: incoming GTP-U: match on local IP, not remote IP
......................................................................
nft: incoming GTP-U: match on local IP, not remote IP
Change-Id: Ib6db148ca350107b2fc7adcaec0fc2930ffcbcde
---
M src/osmo-upf/upf_nft.c
1 file changed, 3 insertions(+), 3 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/osmo-upf refs/changes/92/30492/1
diff --git a/src/osmo-upf/upf_nft.c b/src/osmo-upf/upf_nft.c
index 1b7d9c0..695ec20 100644
--- a/src/osmo-upf/upf_nft.c
+++ b/src/osmo-upf/upf_nft.c
@@ -129,9 +129,9 @@
/* Match only UDP packets */
OSMO_STRBUF_PRINTF(sb, " meta l4proto udp");
- /* Match on packets coming in from from_peer */
- OSMO_STRBUF_PRINTF(sb, " ip saddr ");
- OSMO_STRBUF_APPEND(sb, osmo_sockaddr_to_str_buf2, from_peer->addr_remote);
+ /* Match on packets coming in at specific local IP */
+ OSMO_STRBUF_PRINTF(sb, " ip daddr ");
+ OSMO_STRBUF_APPEND(sb, osmo_sockaddr_to_str_buf2, from_peer->addr_local);
/* Match on the TEID in the header */
OSMO_STRBUF_PRINTF(sb, " @ih,32,32 0x%08x", from_peer->teid_local);
--
To view, visit https://gerrit.osmocom.org/c/osmo-upf/+/30492
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: osmo-upf
Gerrit-Branch: master
Gerrit-Change-Id: Ib6db148ca350107b2fc7adcaec0fc2930ffcbcde
Gerrit-Change-Number: 30492
Gerrit-PatchSet: 1
Gerrit-Owner: neels <nhofmeyr(a)sysmocom.de>
Gerrit-MessageType: newchange
neels has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-upf/+/30495 )
Change subject: nft: end each rule in semicolon
......................................................................
nft: end each rule in semicolon
also cosmetic: put the line ending in a separate PRINTF so that adding
or removing items to the rule in future patches does not affect the line
ending.
Change-Id: I6ff6f59fb24a18596aa60848fb00ac70deb1985f
---
M src/osmo-upf/upf_nft.c
1 file changed, 2 insertions(+), 1 deletion(-)
git pull ssh://gerrit.osmocom.org:29418/osmo-upf refs/changes/95/30495/1
diff --git a/src/osmo-upf/upf_nft.c b/src/osmo-upf/upf_nft.c
index 0b270ff..4dfea6c 100644
--- a/src/osmo-upf/upf_nft.c
+++ b/src/osmo-upf/upf_nft.c
@@ -149,7 +149,8 @@
/* Change the TEID in the header to the one to_peer expects */
OSMO_STRBUF_PRINTF(sb, " @ih,32,32 set 0x%08x", to_peer->teid_remote);
- OSMO_STRBUF_PRINTF(sb, " counter\n");
+ OSMO_STRBUF_PRINTF(sb, " counter");
+ OSMO_STRBUF_PRINTF(sb, ";\n");
return sb.chars_needed;
}
--
To view, visit https://gerrit.osmocom.org/c/osmo-upf/+/30495
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: osmo-upf
Gerrit-Branch: master
Gerrit-Change-Id: I6ff6f59fb24a18596aa60848fb00ac70deb1985f
Gerrit-Change-Number: 30495
Gerrit-PatchSet: 1
Gerrit-Owner: neels <nhofmeyr(a)sysmocom.de>
Gerrit-MessageType: newchange
neels has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-upf/+/30496 )
Change subject: nft: ensure to assign rule id only once
......................................................................
nft: ensure to assign rule id only once
Make sure an assigned id is not overwritten.
So far this function was guaranteed to be called only once. But I would
like to allow getting the nftables ruleset string more than once in a
future patch. Prepare that.
Change-Id: I4e8c48c01fb2f5d4cfd223fe03abbf15b1a55670
---
M include/osmocom/upf/upf_nft.h
M src/osmo-upf/upf_nft.c
2 files changed, 7 insertions(+), 2 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/osmo-upf refs/changes/96/30496/1
diff --git a/include/osmocom/upf/upf_nft.h b/include/osmocom/upf/upf_nft.h
index 9108a4f..fe8bb12 100644
--- a/include/osmocom/upf/upf_nft.h
+++ b/include/osmocom/upf/upf_nft.h
@@ -42,6 +42,7 @@
struct osmo_sockaddr gtp_remote_addr;
uint32_t remote_teid;
} core;
+ /* id as in ruleset name 'tunmap<id>'. If zero, no id has been assigned yet. */
uint32_t id;
};
diff --git a/src/osmo-upf/upf_nft.c b/src/osmo-upf/upf_nft.c
index 4dfea6c..c34cbfb 100644
--- a/src/osmo-upf/upf_nft.c
+++ b/src/osmo-upf/upf_nft.c
@@ -215,8 +215,12 @@
struct upf_nft_args args;
/* Give this tunnel mapping a new id, returned to the caller so that the tunnel mapping can be deleted later */
- g_upf->nft.next_id_state++;
- tunmap->id = g_upf->nft.next_id_state;
+ if (!tunmap->id) {
+ g_upf->nft.next_id_state++;
+ if (!g_upf->nft.next_id_state)
+ g_upf->nft.next_id_state++;
+ tunmap->id = g_upf->nft.next_id_state;
+ }
upf_nft_args_from_tunmap_desc(&args, tunmap);
return upf_nft_run(upf_nft_ruleset_tunmap_create_c(OTC_SELECT, &args));
--
To view, visit https://gerrit.osmocom.org/c/osmo-upf/+/30496
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings
Gerrit-Project: osmo-upf
Gerrit-Branch: master
Gerrit-Change-Id: I4e8c48c01fb2f5d4cfd223fe03abbf15b1a55670
Gerrit-Change-Number: 30496
Gerrit-PatchSet: 1
Gerrit-Owner: neels <nhofmeyr(a)sysmocom.de>
Gerrit-MessageType: newchange