cosmetic: rename g_upf->gtp to tunend, ->nft to tunmap

Upcoming patch I8eae5b53c563400ddfded264678d9cfb28b6f737 will introduce
a g_upf->gtp sub struct for more generally GTP related things (local
TEID assignment).

Change-Id: I74df838af50f38604e2ff06cac0af11ccfdab386
This commit is contained in:
Neels Janosch Hofmeyr
2023-02-10 22:40:03 +01:00
parent 0a87f42f10
commit 1961cf90b5
7 changed files with 63 additions and 63 deletions

View File

@@ -68,7 +68,7 @@ struct tunend_vty_cfg_dev {
struct tunend_vty_cfg {
/* list of struct tunend_vty_cfg_dev, GTP devices as in the config file. The actual GTP devices in use are in
* g_upf->gtp.devs. */
* g_upf->tunend.devs. */
struct llist_head devs;
};
@@ -101,7 +101,7 @@ struct g_upf {
int32_t genl_id;
uint8_t recovery_count;
} gtp;
} tunend;
/* Tunnel forwarding via linux netfilter */
struct {
@@ -113,7 +113,7 @@ struct g_upf {
int priority_pre;
int priority_post;
uint32_t next_chain_id_state;
} nft;
} tunmap;
struct llist_head netinst;
};

View File

@@ -84,7 +84,7 @@ static int up_gtp_action_enable_disable(struct up_gtp_action *a, bool enable)
switch (a->kind) {
case UP_GTP_U_TUNEND:
if (g_upf->gtp.mockup) {
if (g_upf->tunend.mockup) {
LOG_UP_GTP_ACTION(a, LOGL_NOTICE, "tunend/mockup active, skipping GTP action %s\n",
enable ? "enable" : "disable");
return 0;
@@ -116,7 +116,7 @@ static int up_gtp_action_enable_disable(struct up_gtp_action *a, bool enable)
return 0;
case UP_GTP_U_TUNMAP:
if (g_upf->nft.mockup) {
if (g_upf->tunmap.mockup) {
LOG_UP_GTP_ACTION(a, LOGL_NOTICE, "tunmap/mockup active, skipping nftables ruleset %s\n",
enable ? "enable" : "disable");
return 0;

View File

@@ -50,18 +50,18 @@ void g_upf_alloc(void *ctx)
.local_port = OSMO_PFCP_PORT,
},
},
.nft = {
.tunmap = {
.priority_pre = -300,
.priority_post = 400,
},
.gtp = {
.tunend = {
/* TODO: recovery count state file; use lower byte of current time, poor person's random. */
.recovery_count = time(NULL),
},
};
INIT_LLIST_HEAD(&g_upf->gtp.vty_cfg.devs);
INIT_LLIST_HEAD(&g_upf->gtp.devs);
INIT_LLIST_HEAD(&g_upf->tunend.vty_cfg.devs);
INIT_LLIST_HEAD(&g_upf->tunend.devs);
INIT_LLIST_HEAD(&g_upf->netinst);
}
@@ -89,7 +89,7 @@ int upf_pfcp_listen()
int upf_gtp_devs_open()
{
struct tunend_vty_cfg *c = &g_upf->gtp.vty_cfg;
struct tunend_vty_cfg *c = &g_upf->tunend.vty_cfg;
struct tunend_vty_cfg_dev *d;
llist_for_each_entry(d, &c->devs, entry) {

View File

@@ -66,7 +66,7 @@ char *upf_gtp_dev_to_str_c(void *ctx, const struct upf_gtp_dev *dev)
struct upf_gtp_dev *upf_gtp_dev_find_by_name(const char *name)
{
struct upf_gtp_dev *dev;
llist_for_each_entry(dev, &g_upf->gtp.devs, entry) {
llist_for_each_entry(dev, &g_upf->tunend.devs, entry) {
if (!strcmp(name, dev->name))
return dev;
}
@@ -79,7 +79,7 @@ struct upf_gtp_dev *upf_gtp_dev_find_by_local_addr(const struct osmo_sockaddr *l
struct upf_gtp_dev *dev_any = NULL;
struct osmo_sockaddr needle = *local_addr;
llist_for_each_entry(dev, &g_upf->gtp.devs, entry) {
llist_for_each_entry(dev, &g_upf->tunend.devs, entry) {
/* To leave the port number out of the cmp, set the needle's port to match */
osmo_sockaddr_set_port(&needle.u.sa, osmo_sockaddr_port(&dev->gtpv1.local_addr.u.sa));
@@ -95,7 +95,7 @@ struct upf_gtp_dev *upf_gtp_dev_find_by_local_addr(const struct osmo_sockaddr *l
struct upf_gtp_dev *upf_gtp_dev_first()
{
return llist_first_entry_or_null(&g_upf->gtp.devs, struct upf_gtp_dev, entry);
return llist_first_entry_or_null(&g_upf->tunend.devs, struct upf_gtp_dev, entry);
}
/* Tell the kernel to remove the GTP device. Called implicitly by talloc_free() (see upf_gtp_dev_destruct()). */
@@ -116,7 +116,7 @@ static int upf_gtp_dev_delete(struct upf_gtp_dev *dev)
static int upf_gtp_dev_destruct(struct upf_gtp_dev *dev);
/* Allocate state for one GTP device, add to g_upf->gtp.devs and return the created device. If state for the device of
/* Allocate state for one GTP device, add to g_upf->tunend.devs and return the created device. If state for the device of
* that name already exists, do nothing and return NULL. */
static struct upf_gtp_dev *upf_gtp_dev_alloc(const char *name, const char *local_addr)
{
@@ -144,7 +144,7 @@ static struct upf_gtp_dev *upf_gtp_dev_alloc(const char *name, const char *local
/* Need to add to list before setting up the destructor. A talloc_free() does automagically remove from the
* list. */
llist_add(&dev->entry, &g_upf->gtp.devs);
llist_add(&dev->entry, &g_upf->tunend.devs);
talloc_set_destructor(dev, upf_gtp_dev_destruct);
@@ -163,7 +163,7 @@ static int dev_resolve_ifidx(struct upf_gtp_dev *dev)
}
/* Let's try something to see if talking to the device works. */
errno = 0;
rc = gtp_list_tunnel(g_upf->gtp.genl_id, g_upf->gtp.nl);
rc = gtp_list_tunnel(g_upf->tunend.genl_id, g_upf->tunend.nl);
if (errno)
rc = -errno;
else if (rc)
@@ -192,7 +192,7 @@ int upf_gtp_dev_open(const char *name, bool create_gtp_dev, const char *local_ad
int rc;
struct upf_gtp_dev *dev;
if (g_upf->gtp.mockup) {
if (g_upf->tunend.mockup) {
LOGP(DGTP, LOGL_NOTICE, "tunend/mockup active: not opening GTP device '%s'\n", name);
return 0;
}
@@ -265,17 +265,17 @@ int upf_gtp_dev_open(const char *name, bool create_gtp_dev, const char *local_ad
void upf_gtp_devs_close()
{
struct upf_gtp_dev *dev;
while ((dev = llist_first_entry_or_null(&g_upf->gtp.devs, struct upf_gtp_dev, entry)))
while ((dev = llist_first_entry_or_null(&g_upf->tunend.devs, struct upf_gtp_dev, entry)))
talloc_free(dev);
}
void upf_gtp_genl_close()
{
if (!g_upf->gtp.nl)
if (!g_upf->tunend.nl)
return;
genl_socket_close(g_upf->gtp.nl);
g_upf->gtp.nl = NULL;
g_upf->gtp.genl_id = -1;
genl_socket_close(g_upf->tunend.nl);
g_upf->tunend.nl = NULL;
g_upf->tunend.genl_id = -1;
LOGP(DGTP, LOGL_NOTICE, "Closed mnl_socket\n");
}
@@ -284,21 +284,21 @@ void upf_gtp_genl_close()
int upf_gtp_genl_ensure_open()
{
/* Already open? */
if (g_upf->gtp.nl && g_upf->gtp.genl_id >= 0)
if (g_upf->tunend.nl && g_upf->tunend.genl_id >= 0)
return 0;
/* sanity / paranoia: if re-opening, make sure the previous socket is closed */
if (g_upf->gtp.nl)
if (g_upf->tunend.nl)
upf_gtp_genl_close();
g_upf->gtp.nl = genl_socket_open();
if (!g_upf->gtp.nl) {
g_upf->tunend.nl = genl_socket_open();
if (!g_upf->tunend.nl) {
LOGP(DGTP, LOGL_ERROR, "Cannot open mnl_socket: %s\n", strerror(errno));
return -EIO;
}
g_upf->gtp.genl_id = genl_lookup_family(g_upf->gtp.nl, "gtp");
if (g_upf->gtp.genl_id < 0) {
g_upf->tunend.genl_id = genl_lookup_family(g_upf->tunend.nl, "gtp");
if (g_upf->tunend.genl_id < 0) {
LOGP(DGTP, LOGL_ERROR, "genl family 'gtp' not found\n");
return -ENOTSUP;
}
@@ -398,7 +398,7 @@ int upf_gtp_tunend_activate(struct upf_gtp_tunend *tun)
return -ENOTSUP;
errno = 0;
rc = gtp_add_tunnel(g_upf->gtp.genl_id, g_upf->gtp.nl, t);
rc = gtp_add_tunnel(g_upf->tunend.genl_id, g_upf->tunend.nl, t);
if (errno) {
rc = -errno;
} else if (rc) {
@@ -466,7 +466,7 @@ static int upf_gtp_tunend_deactivate(struct upf_gtp_tunend *tun)
if (!t)
return -EINVAL;
rc = gtp_del_tunnel(g_upf->gtp.genl_id, g_upf->gtp.nl, t);
rc = gtp_del_tunnel(g_upf->tunend.genl_id, g_upf->tunend.nl, t);
if (rc)
LOG_GTP_TUN(tun, LOGL_ERROR, "Failed to delete tunnel\n");
else

View File

@@ -84,7 +84,7 @@ static int tx_echo_resp(struct upf_gtp_dev *dev, const struct osmo_sockaddr *rem
/* ECHO RESPONSE shall contain a recovery counter */
msgb_put_u8(msg, GTP1U_IEI_RECOVERY);
msgb_put_u8(msg, g_upf->gtp.recovery_count);
msgb_put_u8(msg, g_upf->tunend.recovery_count);
osmo_store16be(msg->tail - tx_h->data1, &tx_h->length);

View File

@@ -63,18 +63,18 @@ static int upf_nft_run(const char *ruleset)
{
int rc;
if (g_upf->nft.mockup) {
if (g_upf->tunmap.mockup) {
LOGP(DNFT, LOGL_NOTICE, "tunmap/mockup active: not running nft ruleset: '%s'\n", ruleset);
return 0;
}
if (!g_upf->nft.nft_ctx) {
if (!g_upf->tunmap.nft_ctx) {
rc = upf_nft_init();
if (rc)
return rc;
}
rc = nft_run_cmd_from_buffer(g_upf->nft.nft_ctx, ruleset);
rc = nft_run_cmd_from_buffer(g_upf->tunmap.nft_ctx, ruleset);
if (rc < 0) {
LOGP(DNFT, LOGL_ERROR, "error running nft ruleset: rc=%d ruleset=%s\n",
rc, osmo_quote_str_c(OTC_SELECT, ruleset, -1));
@@ -90,18 +90,18 @@ 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");
if (!g_upf->tunmap.table_name)
g_upf->tunmap.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) {
if (g_upf->tunmap.mockup) {
LOGP(DNFT, LOGL_NOTICE,
"tunmap/mockup active: not allocating libnftables nft_ctx. FOR TESTING PURPOSES ONLY.\n");
return 0;
}
g_upf->nft.nft_ctx = nft_ctx_new(NFT_CTX_DEFAULT);
if (!g_upf->nft.nft_ctx) {
g_upf->tunmap.nft_ctx = nft_ctx_new(NFT_CTX_DEFAULT);
if (!g_upf->tunmap.nft_ctx) {
LOGP(DNFT, LOGL_ERROR, "cannot allocate libnftables nft_ctx\n");
return -EIO;
}
@@ -109,14 +109,14 @@ int upf_nft_init()
rc = upf_nft_run(upf_nft_tunmap_get_table_init_str(OTC_SELECT));
if (rc) {
LOGP(DNFT, LOGL_ERROR, "Failed to create nft table %s\n",
osmo_quote_str_c(OTC_SELECT, g_upf->nft.table_name, -1));
osmo_quote_str_c(OTC_SELECT, g_upf->tunmap.table_name, -1));
return rc;
}
LOGP(DNFT, LOGL_NOTICE, "Created nft table %s\n", osmo_quote_str_c(OTC_SELECT, g_upf->nft.table_name, -1));
LOGP(DNFT, LOGL_NOTICE, "Created nft table %s\n", osmo_quote_str_c(OTC_SELECT, g_upf->tunmap.table_name, -1));
rc = upf_nft_run(upf_nft_tunmap_get_vmap_init_str(OTC_SELECT));
if (rc) {
LOGP(DNFT, LOGL_ERROR, "Failed to initialize nft verdict map in table %s\n", g_upf->nft.table_name);
LOGP(DNFT, LOGL_ERROR, "Failed to initialize nft verdict map in table %s\n", g_upf->tunmap.table_name);
return rc;
}
return 0;
@@ -124,10 +124,10 @@ int upf_nft_init()
int upf_nft_free()
{
if (!g_upf->nft.nft_ctx)
if (!g_upf->tunmap.nft_ctx)
return 0;
nft_ctx_free(g_upf->nft.nft_ctx);
g_upf->nft.nft_ctx = NULL;
nft_ctx_free(g_upf->tunmap.nft_ctx);
g_upf->tunmap.nft_ctx = NULL;
return 0;
}
@@ -314,7 +314,7 @@ static void upf_nft_args_from_tunmap(struct upf_nft_args *args, const struct upf
OSMO_ASSERT(osmo_sockaddr_port(&tunmap->core.tun.local.addr.u.sa) == 0);
*args = (struct upf_nft_args){
.table_name = g_upf->nft.table_name,
.table_name = g_upf->tunmap.table_name,
.peer_a = {
.addr_remote = &tunmap->access.tun.remote.addr,
.teid_remote = tunmap->access.tun.remote.teid,
@@ -334,21 +334,21 @@ static void upf_nft_args_from_tunmap(struct upf_nft_args *args, const struct upf
char *upf_nft_tunmap_get_table_init_str(void *ctx)
{
return upf_nft_ruleset_table_create(ctx, g_upf->nft.table_name);
return upf_nft_ruleset_table_create(ctx, g_upf->tunmap.table_name);
}
char *upf_nft_tunmap_get_vmap_init_str(void *ctx)
{
return upf_nft_ruleset_vmap_init(ctx, g_upf->nft.table_name, g_upf->nft.priority_pre,
g_upf->nft.priority_post);
return upf_nft_ruleset_vmap_init(ctx, g_upf->tunmap.table_name, g_upf->tunmap.priority_pre,
g_upf->tunmap.priority_post);
}
static uint32_t chain_id_next(void)
{
g_upf->nft.next_chain_id_state++;
if (!g_upf->nft.next_chain_id_state)
g_upf->nft.next_chain_id_state++;
return g_upf->nft.next_chain_id_state;
g_upf->tunmap.next_chain_id_state++;
if (!g_upf->tunmap.next_chain_id_state)
g_upf->tunmap.next_chain_id_state++;
return g_upf->tunmap.next_chain_id_state;
}
char *upf_nft_tunmap_get_ruleset_str(void *ctx, struct upf_tunmap *tunmap)

View File

@@ -53,7 +53,7 @@ static struct cmd_node cfg_pfcp_node = {
};
#define pfcp_vty (g_upf->pfcp.vty_cfg)
#define tunend_vty (g_upf->gtp.vty_cfg)
#define tunend_vty (g_upf->tunend.vty_cfg)
DEFUN(cfg_pfcp, cfg_pfcp_cmd,
"pfcp",
@@ -102,7 +102,7 @@ static int config_write_tunend(struct vty *vty)
struct tunend_vty_cfg_dev *d;
vty_out(vty, "tunend%s", VTY_NEWLINE);
if (g_upf->gtp.mockup)
if (g_upf->tunend.mockup)
vty_out(vty, " mockup%s", VTY_NEWLINE);
llist_for_each_entry(d, &tunend_vty.devs, entry) {
@@ -124,7 +124,7 @@ DEFUN(cfg_tunend_mockup, cfg_tunend_mockup_cmd,
"mockup",
"don't actually send commands to the GTP kernel module, just return success\n")
{
g_upf->gtp.mockup = true;
g_upf->tunend.mockup = true;
return CMD_SUCCESS;
}
@@ -133,7 +133,7 @@ DEFUN(cfg_tunend_no_mockup, cfg_tunend_no_mockup_cmd,
NO_STR
"operate GTP kernel module normally\n")
{
g_upf->gtp.mockup = false;
g_upf->tunend.mockup = false;
return CMD_SUCCESS;
}
@@ -224,11 +224,11 @@ static int config_write_tunmap(struct vty *vty)
{
vty_out(vty, "tunmap%s", VTY_NEWLINE);
if (g_upf->nft.mockup)
if (g_upf->tunmap.mockup)
vty_out(vty, " mockup%s", VTY_NEWLINE);
if (g_upf->nft.table_name && strcmp(g_upf->nft.table_name, "osmo-upf"))
vty_out(vty, " table-name %s%s", g_upf->nft.table_name, VTY_NEWLINE);
if (g_upf->tunmap.table_name && strcmp(g_upf->tunmap.table_name, "osmo-upf"))
vty_out(vty, " table-name %s%s", g_upf->tunmap.table_name, VTY_NEWLINE);
return CMD_SUCCESS;
}
@@ -237,7 +237,7 @@ DEFUN(cfg_tunmap_mockup, cfg_tunmap_mockup_cmd,
"mockup",
"don't actually send rulesets to nftables, just return success\n")
{
g_upf->nft.mockup = true;
g_upf->tunmap.mockup = true;
return CMD_SUCCESS;
}
@@ -246,7 +246,7 @@ DEFUN(cfg_tunmap_no_mockup, cfg_tunmap_no_mockup_cmd,
NO_STR
"operate nftables rulesets normally\n")
{
g_upf->nft.mockup = false;
g_upf->tunmap.mockup = false;
return CMD_SUCCESS;
}
@@ -258,7 +258,7 @@ DEFUN(cfg_tunmap_table_name, cfg_tunmap_table_name_cmd,
" The default table name is \"osmo-upf\".\n"
"nft inet table name\n")
{
osmo_talloc_replace_string(g_upf, &g_upf->nft.table_name, argv[0]);
osmo_talloc_replace_string(g_upf, &g_upf->tunmap.table_name, argv[0]);
return CMD_SUCCESS;
}