Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lldp: add supports for lldp protocol #985

Merged
merged 3 commits into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions conf/dpvs.bond.conf.sample
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ global_defs {
! log_async_mode off
! kni on
! pdump off
lldp on
}

! netif config
Expand Down
1 change: 1 addition & 0 deletions conf/dpvs.conf.items
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ global_defs {
<init> log_async_pool_size 16383 <16383, 1023-unlimited>
<init> pdump off <off, on|off>
<init> kni on <on, on|off>
lldp on <off, on|off>
}

! netif config
Expand Down
1 change: 1 addition & 0 deletions conf/dpvs.conf.sample
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ global_defs {
! log_async_mode on
! kni on
! pdump off
lldp on
}

! netif config
Expand Down
1 change: 1 addition & 0 deletions conf/dpvs.conf.single-bond.sample
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ global_defs {
! log_file /var/log/dpvs.log
! log_async_mode on
! kni on
lldp on
}

! netif config
Expand Down
1 change: 1 addition & 0 deletions conf/dpvs.conf.single-nic.sample
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ global_defs {
! log_file /var/log/dpvs.log
! log_async_mode on
! kni on
lldp on
}

! netif config
Expand Down
38 changes: 38 additions & 0 deletions include/conf/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <unistd.h>
#include <ctype.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <linux/if_ether.h>

typedef uint32_t sockoptid_t;
Expand Down Expand Up @@ -142,6 +143,7 @@ int linux_get_link_status(const char *ifname, int *if_flags, char *if_flags_str,
int linux_set_if_mac(const char *ifname, const unsigned char mac[ETH_ALEN]);
int linux_hw_mc_add(const char *ifname, const uint8_t hwma[ETH_ALEN]);
int linux_hw_mc_del(const char *ifname, const uint8_t hwma[ETH_ALEN]);
int linux_ifname2index(const char *ifname);

/* read "n" bytes from a descriptor */
ssize_t readn(int fd, void *vptr, size_t n);
Expand All @@ -166,4 +168,40 @@ static inline char *strlwr(char *str) {
return str;
}

/* convert hexadecimal string to binary sequence, return the converted binary length
* note: buflen should be half in size of len at least */
int hexstr2binary(const char *hexstr, size_t len, uint8_t *buf, size_t buflen);

/* convert binary sequence to hexadecimal string, return the converted string length
* note: buflen should be twice in size of len at least */
int binary2hexstr(const uint8_t *hex, size_t len, char *buf, size_t buflen);

/* convert binary sequence to printable or hexadecimal string, return the converted string length
* note: buflen should be triple in size of len in the worst case */
int binary2print(const uint8_t *hex, size_t len, char *buf, size_t buflen);

/* get prefix from network mask */
int mask2prefix(const struct sockaddr *addr);

/* get host addresses and corresponding interfaces
*
* Loopback addresses, ipv6 link local addresses, and addresses on linked-down
* or not-running interface are ignored. If multiple addresses matched, return
* the address of the least prefix length.
*
* Params:
* @ifname: preferred interface where to get host address, can be NULL
* @result4: store ipv4 address found, can be NULL
* @result6: store ipv6 address found, can be NULL
* @ifname4: interface name of ipv4 address, can be NULL
* @ifname6: interface name of ipv6 address, can be NULL
* Return:
* 1: only ipv4 address found
* 2: only ipv6 address found
* 3: both ipv4 and ipv6 address found
* dpvs error code: error occurred
* */
int get_host_addr(const char *ifname, struct sockaddr_storage *result4,
struct sockaddr_storage *result6, char *ifname4, char *ifname6);

#endif /* __DPVS_COMMON_H__ */
41 changes: 41 additions & 0 deletions include/conf/lldp.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* DPVS is a software load balancer (Virtual Server) based on DPDK.
*
* Copyright (C) 2021 iQIYI (www.iqiyi.com).
* All Rights Reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#ifndef __DPVS_LLDP_CONF_H__
#define __DPVS_LLDP_CONF_H__

#include <net/if.h>
#include "conf/sockopts.h"

#define LLDP_MESSAGE_LEN 4096

#define DPVS_LLDP_NODE_LOCAL 0
#define DPVS_LLDP_NODE_NEIGH 1
#define DPVS_LLDP_NODE_MAX 2


struct lldp_param {
uint16_t node; /* DPVS_LLDP_NODE_xxx */
char ifname[IFNAMSIZ];
};

struct lldp_message {
struct lldp_param param;
char message[LLDP_MESSAGE_LEN];
};

#endif /* __DPVS_LLDP_CONF_H__ */
3 changes: 3 additions & 0 deletions include/conf/netif.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ typedef struct netif_nic_basic_get
uint16_t ol_tx_ip_csum:1;
uint16_t ol_tx_tcp_csum:1;
uint16_t ol_tx_udp_csum:1;
uint16_t lldp:1;
} netif_nic_basic_get_t;

/* nic statistics specified by port_id */
Expand Down Expand Up @@ -247,6 +248,8 @@ typedef struct netif_nic_set {
uint16_t tc_egress_off:1;
uint16_t tc_ingress_on:1;
uint16_t tc_ingress_off:1;
uint16_t lldp_on:1;
uint16_t lldp_off:1;
} netif_nic_set_t;

typedef struct netif_bond_set {
Expand Down
3 changes: 3 additions & 0 deletions include/conf/sockopts.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@
DPVSMSG(SOCKOPT_NETIF_GET_MADDR)\
DPVSMSG(SOCKOPT_NETIF_GET_MAX) \
\
DPVSMSG(SOCKOPT_SET_LLDP_TODO) \
DPVSMSG(SOCKOPT_GET_LLDP_SHOW) \
\
DPVSMSG(SOCKOPT_SET_NEIGH_ADD) \
DPVSMSG(SOCKOPT_SET_NEIGH_DEL) \
DPVSMSG(SOCKOPT_GET_NEIGH_SHOW) \
Expand Down
1 change: 1 addition & 0 deletions include/ctrl.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ int msg_dump(const struct dpvs_msg *msg, char *buf, int len);
#define MSG_TYPE_IPV6_STATS 16
#define MSG_TYPE_ROUTE6 17
#define MSG_TYPE_NEIGH_GET 18
#define MSG_TYPE_LLDP_RECV 19
#define MSG_TYPE_IFA_GET 22
#define MSG_TYPE_IFA_SET 23
#define MSG_TYPE_IFA_SYNC 24
Expand Down
118 changes: 118 additions & 0 deletions include/lldp.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/*
* DPVS is a software load balancer (Virtual Server) based on DPDK.
*
* Copyright (C) 2021 iQIYI (www.iqiyi.com).
* All Rights Reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/

#ifndef __DPVS_LLDP_H__
#define __DPVS_LLDP_H__

#define DPVS_LLDP_TYPE_MAX 128

/* IEEE 802.3AB Clause 9: TLV Types */
enum {
LLDP_TYPE_END = 0,
LLDP_TYPE_CHASSIS_ID = 1,
LLDP_TYPE_PORT_ID = 2,
LLDP_TYPE_TTL = 3,
LLDP_TYPE_PORT_DESC = 4,
LLDP_TYPE_SYS_NAME = 5,
LLDP_TYPE_SYS_DESC = 6,
LLDP_TYPE_SYS_CAP = 7,
LLDP_TYPE_MNG_ADDR = 8,
LLDP_TYPE_ORG = 127,
};
#define LLDP_TYPE_VALID(t) (((t) >= 0) && ((t) < DPVS_LLDP_TYPE_MAX))

/* IEEE 802.3AB Clause 9.5.2: Chassis subtypes */
enum {
LLDP_CHASSIS_ID_RESERVED = 0,
LLDP_CHASSIS_ID_CHASSIS_COMPONENT = 1,
LLDP_CHASSIS_ID_INTERFACE_ALIAS = 2,
LLDP_CHASSIS_ID_PORT_COMPONENT = 3,
LLDP_CHASSIS_ID_MAC_ADDRESS = 4,
LLDP_CHASSIS_ID_NETWORK_ADDRESS = 5,
LLDP_CHASSIS_ID_INTERFACE_NAME = 6,
LLDP_CHASSIS_ID_LOCALLY_ASSIGNED = 7,
};
#define LLDP_CHASSIS_ID_VALID(t) (((t) > 0) && ((t) <= 7))

/* IEEE 802.3AB Clause 9.5.3: Port subtype */
enum {
LLDP_PORT_ID_RESERVED = 0,
LLDP_PORT_ID_INTERFACE_ALIAS = 1,
LLDP_PORT_ID_PORT_COMPONENT = 2,
LLDP_PORT_ID_MAC_ADDRESS = 3,
LLDP_PORT_ID_NETWORK_ADDRESS = 4,
LLDP_PORT_ID_INTERFACE_NAME = 5,
LLDP_PORT_ID_AGENT_CIRCUIT_ID = 6,
LLDP_PORT_ID_LOCALLY_ASSIGNED = 7,
};
#define LLDP_PORT_ID_VALID(t) (((t) > 0) && ((t) <= 7))

/*
* IETF RFC 3232:
* http://www.iana.org/assignments/ianaaddressfamilynumbers-mib
*/
enum {
LLDP_ADDR_OTHER = 0,
LLDP_ADDR_IPV4 = 1,
LLDP_ADDR_IPV6 = 2,
LLDP_ADDR_NSAP = 3,
LLDP_ADDR_HDLC = 4,
LLDP_ADDR_BBN1822 = 5,
LLDP_ADDR_ALL802 = 6,
LLDP_ADDR_E163 = 7,
LLDP_ADDR_E164 = 8,
LLDP_ADDR_F69 = 9,
LLDP_ADDR_X121 = 10,
LLDP_ADDR_IPX = 11,
LLDP_ADDR_APPLETALK = 12,
LLDP_ADDR_DECNETIV = 13,
LLDP_ADDR_BANYANVINES = 14,
LLDP_ADDR_E164WITHNSAP = 15,
LLDP_ADDR_DNS = 16,
LLDP_ADDR_DISTINGUISHEDNAME = 17,
LLDP_ADDR_ASNUMBER = 18,
LLDP_ADDR_XTPOVERIPV4 = 19,
LLDP_ADDR_XTPOVERIPV6 = 20,
LLDP_ADDR_XTPNATIVEMODEXTP = 21,
LLDP_ADDR_FIBRECHANNELWWPN = 22,
LLDP_ADDR_FIBRECHANNELWWNN = 23,
LLDP_ADDR_GWID = 24,
LLDP_ADDR_AFI = 25,
LLDP_ADDR_RESERVED = 65535,
};

/* IEEE 802.1AB: Annex E, Table E.1: Organizationally Specific TLVs */
enum {
LLDP_ORG_SPEC_PVID = 1,
LLDP_ORG_SPEC_PPVID = 2,
LLDP_ORG_SPEC_VLAN_NAME = 3,
LLDP_ORG_SPEC_PROTO_ID = 4,
LLDP_ORG_SPEC_VID_USAGE = 5,
LLDP_ORG_SPEC_MGMT_VID = 6,
LLDP_ORG_SPEC_LINK_AGGR = 7,
};
#define LLDP_ORG_SPEC_VALID(t) (((t) > 0) && ((t) <= 7))

void dpvs_lldp_enable(void);
void dpvs_lldp_disable(void);
bool dpvs_lldp_is_enabled(void);

int dpvs_lldp_init(void);
int dpvs_lldp_term(void);

#endif
1 change: 1 addition & 0 deletions include/mbuf.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ typedef void * mbuf_userdata_field_route_t;
typedef enum {
MBUF_FIELD_PROTO = 0,
MBUF_FIELD_ROUTE,
MBUF_FIELD_ORIGIN_PORT,
} mbuf_usedata_field_t;

/**
Expand Down
9 changes: 7 additions & 2 deletions include/netif.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ enum {
NETIF_PORT_FLAG_TC_EGRESS = (0x1<<10),
NETIF_PORT_FLAG_TC_INGRESS = (0x1<<11),
NETIF_PORT_FLAG_NO_ARP = (0x1<<12),
NETIF_PORT_FLAG_LLDP = (0x1<<13),
};

/* max tx/rx queue number for each nic */
Expand Down Expand Up @@ -262,11 +263,15 @@ int netif_unregister_pkt(struct pkt_type *pt);

/**************************** port API ******************************/
struct netif_port* netif_port_get(portid_t id);
/* get netif by name, fail return NULL */
struct netif_port* netif_port_get_by_name(const char *name);
bool is_physical_port(portid_t pid);
bool is_bond_port(portid_t pid);
void netif_physical_port_range(portid_t *start, portid_t *end);
void netif_bond_port_range(portid_t *start, portid_t *end);
/* port_conf can be NULL for default port configure */
int netif_print_port_conf(const struct rte_eth_conf *port_conf, char *buf, int *len);
int netif_print_port_queue_conf(portid_t pid, char *buf, int *len);
/* get netif by name, fail return NULL */
struct netif_port* netif_port_get_by_name(const char *name);
// function only for init or termination //
int netif_port_conf_get(struct netif_port *port, struct rte_eth_conf *eth_conf);
int netif_port_conf_set(struct netif_port *port, const struct rte_eth_conf *conf);
Expand Down
1 change: 1 addition & 0 deletions include/timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/
#ifndef __DPVS_TIMER_H__
#define __DPVS_TIMER_H__
#include <stdint.h>
#include <sys/time.h>
#include "list.h"

Expand Down
Loading
Loading