From 5c84990d9f517c15faa1ebb0057ed61b8014f444 Mon Sep 17 00:00:00 2001 From: Ibtisam Tariq Date: Sat, 30 Oct 2021 10:01:53 +0500 Subject: [PATCH] Add support to set interface name of each port in `config.ini`. --- config.ini | 2 ++ lib/ff_config.c | 4 +++- lib/ff_config.h | 1 + lib/ff_veth.c | 6 +++++- 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/config.ini b/config.ini index e1aebeba7..9baf589ee 100644 --- a/config.ini +++ b/config.ini @@ -84,6 +84,8 @@ addr=192.168.1.2 netmask=255.255.225.0 broadcast=192.168.1.255 gateway=192.168.1.1 +# set interface name, Optional parameter. +#if_name=eno7 # IPv6 net addr, Optional parameters. #addr6=ff::02 diff --git a/lib/ff_config.c b/lib/ff_config.c index e8d8301be..4d9269d81 100644 --- a/lib/ff_config.c +++ b/lib/ff_config.c @@ -489,7 +489,9 @@ port_cfg_handler(struct ff_config *cfg, const char *section, cur->port_id = portid; } - if (strcmp(name, "addr") == 0) { + if (strcmp(name, "ifc_name") == 0) { + cur->ifname = strdup(value); + } else if (strcmp(name, "addr") == 0) { cur->addr = strdup(value); } else if (strcmp(name, "netmask") == 0) { cur->netmask = strdup(value); diff --git a/lib/ff_config.h b/lib/ff_config.h index 10bc2bcdc..30d7d4052 100644 --- a/lib/ff_config.h +++ b/lib/ff_config.h @@ -56,6 +56,7 @@ struct ff_hw_features { struct ff_port_cfg { char *name; + char *ifname; uint8_t port_id; uint8_t mac[6]; struct ff_hw_features hw_features; diff --git a/lib/ff_veth.c b/lib/ff_veth.c index 3aea24ae7..0f75faa90 100644 --- a/lib/ff_veth.c +++ b/lib/ff_veth.c @@ -617,7 +617,11 @@ ff_veth_attach(struct ff_port_cfg *cfg) } memset(sc, 0, sizeof(struct ff_veth_softc)); - snprintf(sc->host_ifname, sizeof(sc->host_ifname), ff_IF_NAME, cfg->port_id); + if(cfg->ifname){ + snprintf(sc->host_ifname, sizeof(sc->host_ifname), "%s", cfg->ifname); + } else { + snprintf(sc->host_ifname, sizeof(sc->host_ifname), ff_IF_NAME, cfg->port_id); + } error = ff_veth_config(sc, cfg); if (0 != error) {