Skip to content

Commit

Permalink
inet: fix prolems in ipv6 all-nodes and all-routers address initializ…
Browse files Browse the repository at this point in the history
…ation

- configure the addresses only when ipv6 is enabled
- configure the addresses on vlan devices
- configure the addresses on ip-tunnel devices (though nothing is done)

Signed-off-by: ywc689 <[email protected]>
  • Loading branch information
ywc689 committed Sep 13, 2024
1 parent 257d89f commit db72d09
Show file tree
Hide file tree
Showing 11 changed files with 148 additions and 35 deletions.
1 change: 1 addition & 0 deletions include/ctrl.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ int msg_dump(const struct dpvs_msg *msg, char *buf, int len);
#define MSG_TYPE_IPSET_SET 40
#define MSG_TYPE_DEST_CHECK_NOTIFY_MASTER 41
#define MSG_TYPE_DEST_CHECK_NOTIFY_SLAVES 42
#define MSG_TYPE_IFA_IDEVINIT 43
#define MSG_TYPE_IPVS_RANGE_START 100

/* for svc per_core, refer to service.h*/
Expand Down
8 changes: 7 additions & 1 deletion include/inetaddr.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,19 @@
#include "dpdk.h"
#include "list.h"


enum {
IDEV_F_NO_IPV6 = 0x00000001
};

struct inet_device {
struct netif_port *dev;
struct list_head ifa_list[DPVS_MAX_LCORE]; /* inet_ifaddr list */
struct list_head ifm_list[DPVS_MAX_LCORE]; /* inet_ifmcaddr list*/
uint32_t ifa_cnt[DPVS_MAX_LCORE];
uint32_t ifm_cnt[DPVS_MAX_LCORE];
rte_atomic32_t refcnt; /* not used yet */
uint32_t flags; /* IDEV_F_XXX */
#define this_ifa_list ifa_list[rte_lcore_id()]
#define this_ifm_list ifm_list[rte_lcore_id()]
#define this_ifa_cnt ifa_cnt[rte_lcore_id()]
Expand Down Expand Up @@ -119,7 +125,7 @@ bool inet_chk_mcast_addr(int af, struct netif_port *dev,

void inet_ifaddr_dad_failure(struct inet_ifaddr *ifa);

int idev_add_mcast_init(struct netif_port *dev);
int idev_addr_init(struct inet_device *idev);

int inet_addr_init(void);
int inet_addr_term(void);
Expand Down
2 changes: 2 additions & 0 deletions include/ip_tunnel.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ int ip_tunnel_xmit(struct rte_mbuf *mbuf, struct netif_port *dev,

int ip_tunnel_pull_header(struct rte_mbuf *mbuf, int hlen, __be16 in_proto);

int ip_tunnel_dev_init(struct netif_port *dev);
int ip_tunnel_set_mc_list(struct netif_port *dev);
int ip_tunnel_get_link(struct netif_port *dev, struct rte_eth_link *link);
int ip_tunnel_get_stats(struct netif_port *dev, struct rte_eth_stats *stats);
int ip_tunnel_get_promisc(struct netif_port *dev, bool *promisc);
Expand Down
7 changes: 7 additions & 0 deletions include/ipv6.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@
#define IPV6
#define RTE_LOGTYPE_IPV6 RTE_LOGTYPE_USER1

struct ipv6_config {
unsigned disable:1;
unsigned forwarding:1;
};

const struct ipv6_config *ip6_config_get(void);

/*
* helper functions
*/
Expand Down
79 changes: 65 additions & 14 deletions src/inetaddr.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "sa_pool.h"
#include "ndisc.h"
#include "route.h"
#include "ipv6.h"
#include "route6.h"
#include "inetaddr.h"
#include "conf/inetaddr.h"
Expand Down Expand Up @@ -232,19 +233,13 @@ static int ifa_add_del_mcast(struct inet_ifaddr *ifa, bool add, bool is_master)
}

/* add ipv6 multicast address after port start */
static int __idev_add_mcast_init(void *args)
static int __idev_inet6_mcast_init(struct netif_port *dev)
{
int err;
struct inet_device *idev;
union inet_addr all_nodes, all_routers;
struct rte_ether_addr eaddr_nodes, eaddr_routers;
lcoreid_t cid = rte_lcore_id();
bool is_master = (cid == g_master_lcore_id);
struct netif_port *dev = (struct netif_port *) args;

if (cid >= DPVS_MAX_LCORE)
return EDPVS_OK;
idev = dev_get_idev(dev);
struct inet_device *idev = dev_get_idev(dev);
bool is_master = (rte_lcore_id() == g_master_lcore_id);

memset(&eaddr_nodes, 0, sizeof(eaddr_nodes));
memset(&eaddr_routers, 0, sizeof(eaddr_routers));
Expand Down Expand Up @@ -290,16 +285,54 @@ static int __idev_add_mcast_init(void *args)
return err;
}

int idev_add_mcast_init(struct netif_port *dev)
static int __idev_addr_init(void *args)
{
struct inet_device *idev = args;
assert(idev != NULL && idev->dev != NULL);

if (rte_lcore_id() >= DPVS_MAX_LCORE)
return EDPVS_OK;

return __idev_inet6_mcast_init(idev->dev);
}

int idev_addr_init(struct inet_device *idev)
{
int err;
lcoreid_t cid;
struct dpvs_msg *msg;

// only ipv6 needs address initialization now
if (ip6_config_get()->disable || (idev->flags & IDEV_F_NO_IPV6))
return EDPVS_OK;

if (rte_lcore_id() != rte_get_main_lcore())
return EDPVS_NOTSUPP;

rte_eal_mp_remote_launch(__idev_add_mcast_init, dev, CALL_MAIN);
RTE_LCORE_FOREACH_WORKER(cid) {
err = rte_eal_wait_lcore(cid);
if (unlikely(err < 0))
// do it on master lcore
err = __idev_addr_init(idev);
if (err != EDPVS_OK)
return err;

// do it on slave lcores
if (dpvs_state_get() == DPVS_STATE_NORMAL) {
msg = msg_make(MSG_TYPE_IFA_IDEVINIT, ifa_msg_seq(), DPVS_MSG_MULTICAST,
rte_lcore_id(), sizeof(idev), &idev);
if (unlikely(!msg))
return EDPVS_NOMEM;
err = multicast_msg_send(msg, DPVS_MSG_F_ASYNC, NULL);
if (err != EDPVS_OK) {
msg_destroy(&msg);
return err;
}
msg_destroy(&msg);
} else {
rte_eal_mp_remote_launch(__idev_addr_init, idev, SKIP_MAIN);
RTE_LCORE_FOREACH_WORKER(cid) {
err = rte_eal_wait_lcore(cid);
if (unlikely(err < 0))
return err;
}
}

return EDPVS_OK;
Expand Down Expand Up @@ -1346,6 +1379,17 @@ static int ifa_msg_sync_cb(struct dpvs_msg *msg)
return EDPVS_OK;
}

static int ifa_msg_idevinit_cb(struct dpvs_msg *msg)
{
struct inet_device *idev;

if (unlikely(!msg || msg->len != sizeof(idev)))
return EDPVS_INVAL;
idev = *((struct inet_device **)(msg->data));

return __idev_addr_init(idev);
}

static int __inet_addr_add(const struct ifaddr_action *param)
{
int err;
Expand Down Expand Up @@ -2115,6 +2159,13 @@ static struct dpvs_msg_type ifa_msg_types[] = {
//.cid = rte_get_main_lcore(),
.unicast_msg_cb = ifa_msg_sync_cb,
.multicast_msg_cb = NULL
},
{
.type = MSG_TYPE_IFA_IDEVINIT,
.prio = MSG_PRIO_NORM,
.mode = DPVS_MSG_MULTICAST,
.unicast_msg_cb = ifa_msg_idevinit_cb,
.multicast_msg_cb = NULL,
}
};

Expand Down
3 changes: 2 additions & 1 deletion src/ip_gre.c
Original file line number Diff line number Diff line change
Expand Up @@ -233,12 +233,13 @@ static int gre_dev_init(struct netif_port *dev)

tnl->hlen = gre_calc_hlen(tnl->params.o_flags);

return EDPVS_OK;
return ip_tunnel_dev_init(dev);
}

static struct netif_ops gre_dev_ops = {
.op_init = gre_dev_init,
.op_xmit = gre_xmit,
.op_set_mc_list = ip_tunnel_set_mc_list,
.op_get_link = ip_tunnel_get_link,
.op_get_stats = ip_tunnel_get_stats,
.op_get_promisc = ip_tunnel_get_promisc,
Expand Down
22 changes: 22 additions & 0 deletions src/ip_tunnel.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ static struct netif_port *tunnel_create(struct ip_tunnel_tab *tab,
dev->flag &= ~NETIF_PORT_FLAG_TX_UDP_CSUM_OFFLOAD;
dev->flag &= ~NETIF_PORT_FLAG_LLDP;

dev->in_ptr->flags |= IDEV_F_NO_IPV6;

err = netif_port_register(dev);
if (err != EDPVS_OK) {
netif_free(dev);
Expand Down Expand Up @@ -900,6 +902,26 @@ int ip_tunnel_pull_header(struct rte_mbuf *mbuf, int hlen, __be16 in_proto)
return EDPVS_OK;
}

int ip_tunnel_dev_init(struct netif_port *dev)
{
int err;
struct ip_tunnel *tnl = netif_priv(dev);

err = idev_addr_init(tnl->dev->in_ptr);
if (err != EDPVS_OK)
return err;

return EDPVS_OK;
}

int ip_tunnel_set_mc_list(struct netif_port *dev)
{
// IP tunnel devices need no hw multicast address,
// and should always return success

return EDPVS_OK;
}

int ip_tunnel_get_link(struct netif_port *dev, struct rte_eth_link *link)
{
struct ip_tunnel *tnl = netif_priv(dev);
Expand Down
2 changes: 2 additions & 0 deletions src/ipip.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ static int ipip_xmit(struct rte_mbuf *mbuf, struct netif_port *dev)
}

static struct netif_ops ipip_dev_ops = {
.op_init = ip_tunnel_dev_init,
.op_xmit = ipip_xmit,
.op_set_mc_list = ip_tunnel_set_mc_list,
.op_get_link = ip_tunnel_get_link,
.op_get_stats = ip_tunnel_get_stats,
.op_get_promisc = ip_tunnel_get_promisc,
Expand Down
30 changes: 17 additions & 13 deletions src/ipv6/ipv6.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,12 @@ static rte_rwlock_t inet6_prot_lock;
/*
* IPv6 configures with default values.
*/
static bool conf_ipv6_forwarding = false;
static bool conf_ipv6_disable = false;
static struct ipv6_config ip6_configs;

const struct ipv6_config *ip6_config_get(void)
{
return &ip6_configs;
};

/*
* IPv6 statistics
Expand Down Expand Up @@ -115,13 +119,13 @@ static void ip6_conf_forward(vector_t tokens)
assert(str);

if (strcasecmp(str, "on") == 0)
conf_ipv6_forwarding = true;
ip6_configs.forwarding = 1;
else if (strcasecmp(str, "off") == 0)
conf_ipv6_forwarding = false;
ip6_configs.forwarding = 0;
else
RTE_LOG(WARNING, IPV6, "invalid ipv6:forwarding %s\n", str);

RTE_LOG(INFO, IPV6, "ipv6:forwarding = %s\n", conf_ipv6_forwarding ? "on" : "off");
RTE_LOG(INFO, IPV6, "ipv6:forwarding = %s\n", ip6_configs.forwarding ? "on" : "off");

FREE_PTR(str);
}
Expand All @@ -133,13 +137,13 @@ static void ip6_conf_disable(vector_t tokens)
assert(str);

if (strcasecmp(str, "on") == 0)
conf_ipv6_disable = true;
ip6_configs.disable = 1;
else if (strcasecmp(str, "off") == 0)
conf_ipv6_disable = false;
ip6_configs.disable = 0;
else
RTE_LOG(WARNING, IPV6, "invalid ipv6:disable %s\n", str);

RTE_LOG(INFO, IPV6, "ipv6:disable = %s\n", conf_ipv6_disable ? "on" : "off");
RTE_LOG(INFO, IPV6, "ipv6: %s\n", ip6_configs.disable ? "disabled" : "enabled");

FREE_PTR(str);
}
Expand Down Expand Up @@ -371,7 +375,7 @@ int ip6_output(struct rte_mbuf *mbuf)
mbuf->port = dev->id;

iftraf_pkt_out(AF_INET6, mbuf, dev);
if (unlikely(conf_ipv6_disable)) {
if (unlikely(ip6_configs.disable)) {
IP6_INC_STATS(outdiscards);
if (rt)
route6_put(rt);
Expand Down Expand Up @@ -411,7 +415,7 @@ static int ip6_forward(struct rte_mbuf *mbuf)
int addrtype;
uint32_t mtu;

if (!conf_ipv6_forwarding)
if (!ip6_configs.forwarding)
goto error;

if (mbuf->packet_type != ETH_PKT_HOST)
Expand Down Expand Up @@ -539,7 +543,7 @@ static int ip6_rcv(struct rte_mbuf *mbuf, struct netif_port *dev)
IP6_UPD_PO_STATS(in, mbuf->pkt_len);
iftraf_pkt_in(AF_INET6, mbuf, dev);

if (unlikely(conf_ipv6_disable)) {
if (unlikely(ip6_configs.disable)) {
IP6_INC_STATS(indiscards);
goto drop;
}
Expand Down Expand Up @@ -815,8 +819,8 @@ void ipv6_keyword_value_init(void)
/* KW_TYPE_INIT keyword */
}
/* KW_TYPE NORMAL keyword */
conf_ipv6_forwarding = false;
conf_ipv6_disable = false;
ip6_configs.forwarding = 0;
ip6_configs.disable = 0;

route6_keyword_value_init();
}
Expand Down
17 changes: 11 additions & 6 deletions src/netif.c
Original file line number Diff line number Diff line change
Expand Up @@ -4013,9 +4013,9 @@ int netif_port_start(struct netif_port *port)
if (port->netif_ops->op_update_addr)
port->netif_ops->op_update_addr(port);

/* add in6_addr multicast address */
if ((ret = idev_add_mcast_init(port)) != EDPVS_OK) {
RTE_LOG(WARNING, NETIF, "%s: idev_add_mcast_init failed -- %d(%s)\n",
/* ipv6 default addresses initialization */
if ((ret = idev_addr_init(port->in_ptr)) != EDPVS_OK) {
RTE_LOG(WARNING, NETIF, "%s: idev_addr_init failed -- %d(%s)\n",
__func__, ret, dpvs_strerror(ret));
return ret;
}
Expand Down Expand Up @@ -4053,7 +4053,7 @@ int netif_port_register(struct netif_port *port)
{
struct netif_port *cur;
int hash, nhash;
int err = EDPVS_OK;
int err;

if (unlikely(NULL == port))
return EDPVS_INVAL;
Expand All @@ -4076,10 +4076,15 @@ int netif_port_register(struct netif_port *port)
list_add_tail(&port->nlist, &port_ntab[nhash]);
g_nports++;

if (port->netif_ops->op_init)
if (port->netif_ops->op_init) {
err = port->netif_ops->op_init(port);
if (err != EDPVS_OK) {
netif_port_unregister(port);
return err;
}
}

return err;
return EDPVS_OK;
}

int netif_port_unregister(struct netif_port *port)
Expand Down
12 changes: 12 additions & 0 deletions src/vlan.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,17 @@ static int alloc_vlan_info(struct netif_port *dev)
return EDPVS_OK;
}

static int vlan_dev_init(struct netif_port *dev)
{
int err;

err = idev_addr_init(dev->in_ptr);
if (err != EDPVS_OK)
return err;

return EDPVS_OK;
}

static int vlan_xmit(struct rte_mbuf *mbuf, struct netif_port *dev)
{
struct vlan_dev_priv *vlan = netif_priv(dev);
Expand Down Expand Up @@ -171,6 +182,7 @@ static int vlan_get_stats(struct netif_port *dev, struct rte_eth_stats *stats)
}

static struct netif_ops vlan_netif_ops = {
.op_init = vlan_dev_init,
.op_xmit = vlan_xmit,
.op_set_mc_list = vlan_set_mc_list,
.op_get_queue = vlan_get_queue,
Expand Down

0 comments on commit db72d09

Please sign in to comment.