implementation of IEEE 802.1Qbg in lldpad
Subsystems (2)
Hi,
this set of patches contains the initial implementation of the IEEE 802.1Qbg
standard: code for the exchange of EVB TLVs in LLDP frames to negotiate VSI capabalities as well as VDP VSI TLVs between a host with virtual machines and an adjacent switch.
It supports setting the parameters of the TLV exchange from the command line using lldptool.
VDP profiles consisting of mode,mgrid,typeid,typeidversion,instanceid,mac,vlan can be given to lldpad with lldptool or sent to lldpad via netlink messages from the kernel or another program, e.g. libvirt.
VDP profiles are processed through the VDP/VSI and ECP state machines and sent out in ECP frames.
ACK frames are received and processed through ECP and VDP/VSI state machines.
It implements a VDP bridge role for a port together with a lldptool command to switch a port to the bridge role.
These patches apply against lldpad 0.9.38. Protocol debug messages are now logged to syslog via LLDPAD_* macros and no longer to console. If you want to see them, configure your syslog daemon to collect debug messages and start lldpad with -V 7.
- improved cleanup in case of interface down
- improved checking if a port really exists
- converted all our code to use LLDPAD_ log messages
- addressed Johns comments
- modified EVB TLV defaults
- increase max number of VSIs to 64k
- fixed a number of bugs and memleaks
For more information about lldpad take a look at
http://sourceforge.net/projects/e1000/files/DCB%20Tools/lldpad/
Please review and comment.
Thank you !
Jens
PATCH 1/9 consolidation of MIN and MAX macros in common.h
This patch consolidates a modified version of the already existing MIN macro in lldpad to include/common.h and add a MAX macro.
--- include/common.h | 14 ++++++++++++++ include/dcb_protocol.h | 4 ---- 2 files changed, 14 insertions(+), 4 deletions(-)
include/common.h +14 -0
@@ -387,4 +387,18 @@ typedef int socklen_t;const char *wpa_ssid_txt (u8 *ssid,size_t ssid_len); +#define MIN (x,y) \ + ({ \ + typeof (x) __x = (x); \ + typeof (y) __y = (y); \ + __x < __y ? __x : __y; \ + }) + +#define MAX (x,y) \ + ({ \ + typeof (x) __x = (x); \ + typeof (y) __y = (y); \ + __x > __y ? __x : __y; \ + }) +#endif /* COMMON_H */
include/dcb_protocol.h +0 -4
@@ -58,10 +58,6 @@ typedef enum {#define DUP_DCBX_TLV_LLINK 0x0020#define TOO_MANY_NGHBRS 0x0040 -//#ifndef min /*todo: change to min() -#define MIN (x, y) ((x) < (y) ? x : y) -//#endif -#define INIT_DCB_OUI {0x00,0x1b,0x21}int add_adapter (char *device_name);
Signature · 1 line
1.7.1
PATCH 2/9 implementation of IEEE 802.1Qbg in lldpad, part 1
In reply to Jens OsterkampThis patch contains the first part of an initial implementation of the IEEE 802.1Qbg standard: it implements code for the exchange of EVB capabilities between a host with virtual machines and an adjacent switch. For this it adds a new EVB TLV to LLDP.
Exchange of EVB TLV may be enabled or disabled on a per port basis. Information about the information negotiated by the protocol can be queried on the commandline with lldptool.
This patch adds support for querying and setting parameters used in the exchange of EVB TLV messages.
The parameters that can be set are:
- forwarding mode
- host protocol capabilities (RTE, ECP, VDP)
- no. of supported VSIs
- retransmission timer exponent (RTE)
The parameters are implemented as a local policy: all frames received by an adjacent switch are validated against this policy and taken over where appropriate. Negotiated parameters are stored in lldpads config, picked up again and used at the next start.
The patch applies to lldpad 0.9.38 and still contains code to log protocol activity more verbosely than it would be necessary in the final version.
--- Makefile.am | 10 +- include/lldp.h | 19 ++ include/lldp_evb.h | 80 ++++++ include/lldp_evb_clif.h | 51 ++++ include/lldp_evb_cmds.h | 31 +++ include/lldp_tlv.h | 1 + lldp_evb.c | 672 +++++++++++++++++++++++++++++++++++++++++++++++ lldp_evb_clif.c | 226 ++++++++++++++++ lldp_evb_cmds.c | 522 ++++++++++++++++++++++++++++++++++++ lldpad.c | 2 + lldptool.c | 2 + 11 files changed, 1612 insertions(+), 4 deletions(-) create mode 100644 include/lldp_evb.h create mode 100644 include/lldp_evb_clif.h create mode 100644 include/lldp_evb_cmds.h create mode 100644 lldp_evb.c create mode 100644 lldp_evb_clif.c create mode 100644 lldp_evb_cmds.c
Makefile.am +6 -4
@@ -37,7 +37,7 @@ lldpad_include_HEADERS = include/dcb_types.h include/dcbtool.h \ include/dcb_osdep.h include/clif.h include/lldp_dcbx_cmds.h include/common.h \ include/lldpad.h include/os.h include/includes.h include/lldp_mand_cmds.h \ include/clif_msgs.h include/lldp_basman_cmds.h include/lldp_8023_cmds.h \ -include/lldp_med_cmds.h include/lldp_dcbx_cfg.h +include/lldp_med_cmds.h include/lldp_dcbx_cfg.h include/lldp_evb_cmds.h noinst_HEADERS = include/config.h include/ctrl_iface.h \ include/dcb_driver_if_types.h include/dcb_driver_interface.h \
@@ -47,7 +47,7 @@ include/event_iface.h include/messages.h include/parse_cli.h include/version.h \ include/lldptool_cli.h include/list.h \ include/lldp_mand_clif.h include/lldp_basman_clif.h include/lldp_med_clif.h \ include/lldp_8023_clif.h include/lldp_dcbx_clif.h include/lldptool.h \ -include/lldp_rtnl.h +include/lldp_rtnl.h include/lldp_evb_clif.h lldpad_SOURCES = lldpad.c config.c drv_cfg.c ctrl_iface.c event_iface.c eloop.c \ common.c os_unix.c lldp_dcbx_cmds.c log.c lldpad_shm.c \
@@ -62,10 +62,12 @@ lldp_dcbx_cfg.c include/lldp_dcbx_cfg.h \ lldp_util.c include/lldp_util.h \ lldp_mand.c include/lldp_mand.h \ lldp_mand_cmds.c lldp_basman_cmds.c lldp_8023_cmds.c lldp_med_cmds.c \ +lldp_evb_cmds.c \ lldp_tlv.c include/lldp_tlv.h \ lldp_basman.c include/lldp_basman.h \ lldp_med.c include/lldp_med.h \ -lldp_8023.c include/lldp_8023.h +lldp_8023.c include/lldp_8023.h \ +lldp_evb.c include/lldp_evb.h
@@ -74,7 +76,7 @@ $(lldpad_include_HEADERS) $(noinst_HEADERS) lldptool_SOURCES = lldptool.c clif.c lldptool_cmds.c common.c os_unix.c \ lldp_mand_clif.c lldp_basman_clif.c lldp_med_clif.c lldp_8023_clif.c \ -lldp_dcbx_clif.c $(lldpad_include_HEADERS) $(noinst_HEADERS) +lldp_dcbx_clif.c lldp_evb_clif.c $(lldpad_include_HEADERS) $(noinst_HEADERS) nltest_SOURCES = nltest.c nltest.h
include/lldp.h +19 -0
@@ -45,6 +45,8 @@/* Telecommunications Industry Association TR-41 Committee */ #define OUI_TIA_TR41 0x0012bb +#define OUI_IEEE_8021Qbg 0x001b3f +/* IEEE 802.3AB Clause 9: TLV Types */ #define CHASSIS_ID_TLV 1#define PORT_ID_TLV 2
@@ -186,5 +188,22 @@ enum {#define LLDP_8023_LINKAGG_CAPABLE (1 << 0)#define LLDP_8023_LINKAGG_ENABLED (1 << 1) +/* IEEE 802.1Qbg subtype */ +#define LLDP_EVB_SUBTYPE 0 + +/* forwarding mode */ +#define LLDP_EVB_CAPABILITY_FORWARD_STANDARD (1 << 7) +#define LLDP_EVB_CAPABILITY_FORWARD_REFLECTIVE_RELAY (1 << 6) + +/* EVB supported protocols */ +#define LLDP_EVB_CAPABILITY_PROTOCOL_RTE (1 << 2) +#define LLDP_EVB_CAPABILITY_PROTOCOL_ECP (1 << 1) +#define LLDP_EVB_CAPABILITY_PROTOCOL_VDP (1 << 0) + +/* EVB specific values */ +#define LLDP_EVB_DEFAULT_MAX_VSI 65535 +#define LLDP_EVB_DEFAULT_SVSI 3295 +#define LLDP_EVB_DEFAULT_RTE 15 +void somethingChangedLocal (char *ifname);#endif /* _LLDP_H */
include/lldp_evb.h new file +80 -0
80 lines not on this page · raw message
include/lldp_evb_clif.h new file +51 -0
51 lines not on this page · raw message
include/lldp_evb_cmds.h new file +31 -0
@@ -0,0 +1,31 @@ +/******************************************************************************* + +implementation of EVB TLVs for LLDP +(c) Copyright IBM Corp. 2010 + +Author(s): Jens Osterkamp <[email protected]> + +This program is free software; you can redistribute it and/or modify it +under the terms and conditions of the GNU General Public License, +version 2, as published by the Free Software Foundation. + +This program is distributed in the hope 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. + +You should have received a copy of the GNU General Public License along with +this program; if not, write to the Free Software Foundation, Inc., +51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. + +The full GNU General Public License is included in this distribution in +the file called "COPYING". + +*******************************************************************************/ + +#ifndef _LLDP_EVB_CMDS_H +#define _LLDP_EVB_CMDS_H + +struct arg_handlers *evb_get_arg_handlers (); + +#endif
include/lldp_tlv.h +1 -0
@@ -144,6 +144,7 @@ int tlv_ok(struct unpacked_tlv *tlv);#define TLVID_8021 (sub) TLVID(OUI_IEEE_8021, (sub))#define TLVID_8023 (sub) TLVID(OUI_IEEE_8023, (sub))#define TLVID_MED (sub) TLVID(OUI_TIA_TR41, (sub)) +#define TLVID_8021Qbg (sub) TLVID(OUI_IEEE_8021Qbg, (sub))/* the size in bytes needed for a packed tlv from unpacked tlv */ #define TLVSIZE (t) ((t) ? (2 + (t)->length) : 0)
lldp_evb.c new file +672 -0
672 lines not on this page · raw message
lldp_evb_clif.c new file +226 -0
226 lines not on this page · raw message
lldp_evb_cmds.c new file +522 -0
522 lines not on this page · raw message
lldpad.c +2 -0
@@ -49,6 +49,7 @@#include "lldp_dcbx.h" #include "lldp_med.h" #include "lldp_8023.h" +#include "lldp_evb.h" #include "config.h" #include "lldpad_shm.h" #include "clif.h"
@@ -63,6 +64,7 @@ struct lldp_module *(*register_tlv_table[])(void) = { dcbx_register, med_register, ieee8023_register, + evb_register, NULL, };
lldptool.c +2 -0
@@ -39,6 +39,7 @@#include "lldp_med_clif.h" #include "lldp_8023_clif.h" #include "lldp_dcbx_clif.h" +#include "lldp_evb_clif.h" #include "lldptool.h" #include "lldptool_cli.h" #include "lldp_mod.h"
@@ -156,6 +157,7 @@ struct lldp_module *(*register_tlv_table[])(void) = { ieee8023_cli_register, med_cli_register, dcbx_cli_register, + evb_cli_register, NULL, };
Signature · 1 line
1.7.1
PATCH 3/9 BUGFIX: check for existence of ifup
In reply to Jens Osterkampadded an additional check for existence of the ifup operation. If it does not exist, just skip it.
--- config.c | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-)
config.c +4 -2
@@ -370,8 +370,10 @@ void init_ports(void) }else if (check_link_status (p->if_name)) {add_adapter (p->if_name); -LIST_FOREACH (np, &lldp_head, lldp) - np->ops->lldp_mod_ifup(p->if_name); + LIST_FOREACH(np, &lldp_head, lldp) { +if (np->ops->lldp_mod_ifup) + np->ops->lldp_mod_ifup (p->if_name); + }set_lldp_port_enable_state (p->if_name,1 ); } p++;
Signature · 1 line
1.7.1
PATCH 4/9 implementation of IEEE 802.1Qbg in lldpad, part 2
In reply to Jens OsterkampThis is the implementation of the edge control protocol (ECP) and VSI discovery protocol (VDP) currently being specified in IEEE 802.1Qbg.
This implementation extends the infrastructure defined lldpad to send and receive ECP frames with a new (yet to be defined) ethertype. Received frames are validated and analyzed before the content is handed to the upper layer protocol (ULP, VDP in this case) for further processing. Frames to be transmitted are compiled from VSI (guest interface) profiles registered on a interface.
Reception and transmission of ECP frames is controlled by RX and TX state machines, timeouts are handled timeout functions.
The patch still contains a lot of debug code to allow low-level protocol analysis.
VDP serves as the upper layer protocol (ULP) for TLVs communicated via the ECP protocol.
For this it registers as a new module in lldpad. The VDP module supports a station and a bridge role. As a station, new VSI (virtual station interface) profiles can be registered to the VDP module using lldptool or libvirt. These profiles are then announced to an adjacent switch. Transmitted profiles are processed to the desired state by the VDP station state machine. As a bridge, the VDP module waits for new profiles received in TLVs by ECP. The received profiles are processed to the desired state by a VDP bridge state machine.
VDP module parameters are stored in the "vdp" section under the appropriate interface.
The patch still contains a lot of debug code to allow analysis of VDP protocol behavior.
--- Makefile.am | 10 +- ecp/ecp.c | 102 +++++ ecp/ecp.h | 101 +++++ ecp/ecp_rx.c | 610 ++++++++++++++++++++++++++ ecp/ecp_tx.c | 506 ++++++++++++++++++++++ include/lldp.h | 1 + include/lldp_evb.h | 6 + include/lldp_vdp.h | 159 +++++++ lldp/l2_packet.h | 2 + lldp/ports.h | 11 +- lldp_vdp.c | 1196 ++++++++++++++++++++++++++++++++++++++++++++++++++++ lldpad.c | 2 + 12 files changed, 2699 insertions(+), 7 deletions(-) create mode 100644 ecp/ecp.c create mode 100644 ecp/ecp.h create mode 100644 ecp/ecp_rx.c create mode 100644 ecp/ecp_tx.c create mode 100644 include/lldp_vdp.h create mode 100644 lldp_vdp.c
Makefile.am +6 -4
@@ -56,6 +56,8 @@ $(lldpad_include_HEADERS) $(noinst_HEADERS) \ lldp/ports.c lldp/agent.c lldp/l2_packet_linux.c lldp/tx.c \ lldp/rx.c lldp/agent.h lldp/l2_packet.h lldp/mibdata.h lldp/ports.h \ lldp/states.h \ +ecp/ecp.c ecp/ecp_tx.c \ +ecp/ecp_rx.c \ include/lldp.h include/lldp_mod.h \ lldp_dcbx.c include/lldp_dcbx.h tlv_dcbx.c include/tlv_dcbx.h \ lldp_dcbx_cfg.c include/lldp_dcbx_cfg.h \
@@ -67,16 +69,16 @@ lldp_tlv.c include/lldp_tlv.h \ lldp_basman.c include/lldp_basman.h \ lldp_med.c include/lldp_med.h \ lldp_8023.c include/lldp_8023.h \ -lldp_evb.c include/lldp_evb.h - - +lldp_evb.c include/lldp_evb.h \ +lldp_vdp.c include/lldp_vdp.h dcbtool_SOURCES = dcbtool.c clif.c dcbtool_cmds.c parse_cli.l \ $(lldpad_include_HEADERS) $(noinst_HEADERS) lldptool_SOURCES = lldptool.c clif.c lldptool_cmds.c common.c os_unix.c \ lldp_mand_clif.c lldp_basman_clif.c lldp_med_clif.c lldp_8023_clif.c \ -lldp_dcbx_clif.c lldp_evb_clif.c $(lldpad_include_HEADERS) $(noinst_HEADERS) +lldp_dcbx_clif.c lldp_evb_clif.c $(lldpad_include_HEADERS) \ +$(noinst_HEADERS) nltest_SOURCES = nltest.c nltest.h
ecp/ecp.c new file +102 -0
102 lines not on this page · raw message
ecp/ecp.h new file +101 -0
101 lines not on this page · raw message
ecp/ecp_rx.c new file +610 -0
610 lines not on this page · raw message
ecp/ecp_tx.c new file +506 -0
506 lines not on this page · raw message
include/lldp.h +1 -0
@@ -190,6 +190,7 @@ enum {/* IEEE 802.1Qbg subtype */ #define LLDP_EVB_SUBTYPE 0 +#define LLDP_VDP_SUBTYPE 0x2/* forwarding mode */ #define LLDP_EVB_CAPABILITY_FORWARD_STANDARD (1 << 7)
include/lldp_evb.h +6 -0
@@ -37,6 +37,12 @@ typedef enum {EVB_CONFIRMATION } evb_state; +#define RTE 13 +/* retransmission granularity (RTG) in microseconds */ +#define EVB_RTG 10 +/* retransmission multiplier (RTM) */ +#define EVB_RTM (rte) (2<<(RTE-1)) +struct tlv_info_evb {u8 oui[3 ];u8 sub;
include/lldp_vdp.h new file +159 -0
159 lines not on this page · raw message
lldp/l2_packet.h +2 -0
@@ -36,6 +36,8 @@#define ETH_P_LLDP 0x88cc +/* TODO: use extended ethertype until final ethertype is available */ +#define ETH_P_ECP 0x88b7#define ETH_FRAME_LEN 1514
lldp/ports.h +8 -3
@@ -142,15 +142,20 @@ struct port {u8 portEnabled;u8 prevPortEnabled;u8 adminStatus; -u8 rxChanges; -u16 lldpdu; + +/* protocol specific */ struct l2_packet_data *l2;struct portrx rx;struct porttx tx; -struct porttlvs tlvs;struct portstats stats;struct porttimers timers; +u8 rxChanges; +u16 lldpdu;struct msap msap; + +/* not sure */ +struct porttlvs tlvs; +struct port *next; };
lldp_vdp.c new file +1196 -0
1,196 lines not on this page · raw message
lldpad.c +2 -0
@@ -50,6 +50,7 @@#include "lldp_med.h" #include "lldp_8023.h" #include "lldp_evb.h" +#include "lldp_vdp.h" #include "config.h" #include "lldpad_shm.h" #include "clif.h"
@@ -65,6 +66,7 @@ struct lldp_module *(*register_tlv_table[])(void) = { med_register, ieee8023_register, evb_register, + vdp_register, NULL, };
Signature · 1 line
1.7.1
PATCH 5/9 VDP commandline interface
In reply to Jens OsterkampThis patch implements the command line interface to control the VDP module. In station role, it allows to register a new VSI (guest interface) profile and query its state. In bridge role, it allows to query the state of all registered profiles.
With lldptool it is possible to set the role from default "station" to "bridge".
The configuration of the role for a port is saved to lldpads config file.
--- Makefile.am | 12 +- include/lldp_vdp_clif.h | 39 +++++ include/lldp_vdp_cmds.h | 44 +++++ lldp_vdp_clif.c | 136 ++++++++++++++++ lldp_vdp_cmds.c | 408 +++++++++++++++++++++++++++++++++++++++++++++++ lldptool.c | 2 + 6 files changed, 636 insertions(+), 5 deletions(-) create mode 100644 include/lldp_vdp_clif.h create mode 100644 include/lldp_vdp_cmds.h create mode 100644 lldp_vdp_clif.c create mode 100644 lldp_vdp_cmds.c
Makefile.am +7 -5
@@ -37,7 +37,8 @@ lldpad_include_HEADERS = include/dcb_types.h include/dcbtool.h \ include/dcb_osdep.h include/clif.h include/lldp_dcbx_cmds.h include/common.h \ include/lldpad.h include/os.h include/includes.h include/lldp_mand_cmds.h \ include/clif_msgs.h include/lldp_basman_cmds.h include/lldp_8023_cmds.h \ -include/lldp_med_cmds.h include/lldp_dcbx_cfg.h include/lldp_evb_cmds.h +include/lldp_med_cmds.h include/lldp_dcbx_cfg.h include/lldp_evb_cmds.h \ +include/lldp_vdp_cmds.h noinst_HEADERS = include/config.h include/ctrl_iface.h \ include/dcb_driver_if_types.h include/dcb_driver_interface.h \
@@ -47,7 +48,7 @@ include/event_iface.h include/messages.h include/parse_cli.h include/version.h \ include/lldptool_cli.h include/list.h \ include/lldp_mand_clif.h include/lldp_basman_clif.h include/lldp_med_clif.h \ include/lldp_8023_clif.h include/lldp_dcbx_clif.h include/lldptool.h \ -include/lldp_rtnl.h include/lldp_evb_clif.h +include/lldp_rtnl.h include/lldp_evb_clif.h include/lldp_vdp_clif.h lldpad_SOURCES = lldpad.c config.c drv_cfg.c ctrl_iface.c event_iface.c eloop.c \ common.c os_unix.c lldp_dcbx_cmds.c log.c lldpad_shm.c \
@@ -64,20 +65,21 @@ lldp_dcbx_cfg.c include/lldp_dcbx_cfg.h \ lldp_util.c include/lldp_util.h \ lldp_mand.c include/lldp_mand.h \ lldp_mand_cmds.c lldp_basman_cmds.c lldp_8023_cmds.c lldp_med_cmds.c \ -lldp_evb_cmds.c \ +lldp_evb_cmds.c lldp_vdp_cmds.c \ lldp_tlv.c include/lldp_tlv.h \ lldp_basman.c include/lldp_basman.h \ lldp_med.c include/lldp_med.h \ lldp_8023.c include/lldp_8023.h \ lldp_evb.c include/lldp_evb.h \ -lldp_vdp.c include/lldp_vdp.h +lldp_vdp.c include/lldp_vdp.h \ +lldp_vdp_cmds.h dcbtool_SOURCES = dcbtool.c clif.c dcbtool_cmds.c parse_cli.l \ $(lldpad_include_HEADERS) $(noinst_HEADERS) lldptool_SOURCES = lldptool.c clif.c lldptool_cmds.c common.c os_unix.c \ lldp_mand_clif.c lldp_basman_clif.c lldp_med_clif.c lldp_8023_clif.c \ -lldp_dcbx_clif.c lldp_evb_clif.c $(lldpad_include_HEADERS) \ +lldp_dcbx_clif.c lldp_evb_clif.c lldp_vdp_clif.c $(lldpad_include_HEADERS) \ $(noinst_HEADERS) nltest_SOURCES = nltest.c nltest.h
include/lldp_vdp_clif.h new file +39 -0
@@ -0,0 +1,39 @@ +/******************************************************************************* + +implementation of VDP according to IEEE 802.1Qbg +(c) Copyright IBM Corp. 2010 + +Author(s): Jens Osterkamp <[email protected]> + +This program is free software; you can redistribute it and/or modify it +under the terms and conditions of the GNU General Public License, +version 2, as published by the Free Software Foundation. + +This program is distributed in the hope 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. + +You should have received a copy of the GNU General Public License along with +this program; if not, write to the Free Software Foundation, Inc., +51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. + +The full GNU General Public License is included in this distribution in +the file called "COPYING". + +*******************************************************************************/ + +#ifndef _LLDP_VDP_CLIF_H +#define _LLDP_VDP_CLIF_H + +struct lldp_module *vdp_cli_register (void ); +void vdp_cli_unregister (struct lldp_module *); +int vdp_print_tlv (u32 ,u16 ,char *); + +#define VDP_BUF_SIZE 256 + +#define VDP_PREFIX "vdp" +#define ARG_VDP_MODE "mode" +#define ARG_VDP_ROLE "role" + +#endif
include/lldp_vdp_cmds.h new file +44 -0
44 lines not on this page · raw message
lldp_vdp_clif.c new file +136 -0
136 lines not on this page · raw message
lldp_vdp_cmds.c new file +408 -0
408 lines not on this page · raw message
lldptool.c +2 -0
@@ -40,6 +40,7 @@#include "lldp_8023_clif.h" #include "lldp_dcbx_clif.h" #include "lldp_evb_clif.h" +#include "lldp_vdp_clif.h" #include "lldptool.h" #include "lldptool_cli.h" #include "lldp_mod.h"
@@ -158,6 +159,7 @@ struct lldp_module *(*register_tlv_table[])(void) = { med_cli_register, dcbx_cli_register, evb_cli_register, + vdp_cli_register, NULL, };
Signature · 1 line
1.7.1
PATCH 6/9 add libnl dependency to configure.ac
In reply to Jens Osterkamp--- configure.ac | 5 +++++ 1 files changed, 5 insertions(+), 0 deletions(-)
configure.ac +5 -0
@@ -12,6 +12,11 @@ PKG_CHECK_MODULES(LIBCONFIG, libconfig, AC_SUBST(LIBCONFIG_CFLAGS) AC_SUBST(LIBCONFIG_LIBS) +PKG_CHECK_MODULES(LIBNL, libnl-1 >= 1.1) +AC_SUBST(LIBNL_CFLAGS) +AC_SUBST(LIBNL_LIBS) + +AC_CHECK_LIB(nl, rtnl_link_get_by_name) AC_CONFIG_SUBDIRS([libconfig-1.3.2]) AC_CONFIG_FILES([Makefile include/version.h lldpad.spec lldpad.pc dcbd.pc]) AC_OUTPUT
Signature · 1 line
1.7.1
PATCH 7/9 use connect instead of bind
In reply to Jens Osterkampmodifies the setup of the netlink socket in drv_cfg.c to use pid 0 instead of the processes pid.
Also replaces bind with connect to allow the reception of netlink messages from libvirt.
Preparation patch for communication between libvirt and lldpad.
--- drv_cfg.c | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-)
drv_cfg.c +3 -2
@@ -71,9 +71,9 @@ static int init_socket(void)memset ((void *)&snl,0 ,sizeof (struct sockaddr_nl )); snl.nl_family =AF_NETLINK ; - snl.nl_pid =getpid (); + snl.nl_pid =0 ; -if (bind (sd, (struct sockaddr *)&snl,sizeof (struct sockaddr_nl )) <0 ) { +if (connect (sd, (struct sockaddr *)&snl,sizeof (struct sockaddr_nl )) <0 ) {close (sd);return -EIO ; }
@@ -195,6 +195,7 @@ static struct nlmsghdr *get_msg(unsigned int seq) nlh =NULL ;break ; } +fprintf (stderr,"%s:%s: nlmsg_type: %d\n" , __FILE__, __FUNCTION__, nlh->nlmsg_type);if ((nlh->nlmsg_type ==RTM_GETDCB || nlh->nlmsg_type ==RTM_SETDCB ) && nlh->nlmsg_seq == seq) {
Signature · 1 line
1.7.1
PATCH 8/9 lldpad support for libvirt netlink message
In reply to Jens OsterkampThis code receives a IEEE 802.1Qbg virtual station instance from libvirt in a SETLINK message. The parsed VSI is then handed over to VDP for processing. The VDP state machine processes the VSI while libvirt polls the result using GETLINK.
Requires at least Linux kernel 2.6.35-rc1.
--- event_iface.c | 596 ++++++++++++++++++++++++++++++++++++++++++++++++- include/event_iface.h | 1 + include/lldp_vdp.h | 2 + lldp_vdp.c | 2 +- lldpad.c | 10 + 5 files changed, 600 insertions(+), 11 deletions(-)
event_iface.c +586 -10
@@ -3,6 +3,13 @@ LLDP Agent Daemon (LLDPAD) Software Copyright(c) 2007-2010 Intel Corporation. + implementation of libvirt netlink interface + (c) Copyright IBM Corp. 2010 + + Author(s): Jens Osterkamp <[email protected]> + Stefan Berger <[email protected]> + Gerhard Stenzel <[email protected]> + This program is free software; you can redistribute it and/or modify it under the terms and conditions of the GNU General Public License, version 2, as published by the Free Software Foundation.
@@ -31,12 +38,16 @@#include <sys/socket.h> #include <linux/rtnetlink.h> #include <linux/if.h> +#include <linux/if_link.h> #include <linux/if_vlan.h> #include <linux/sockios.h> #include <syslog.h> #include <unistd.h> +#include <linux/netlink.h> +#include <netlink/msg.h> #include "lldpad.h" #include "lldp_mod.h" +#include "lldp_vdp.h" #include "common.h" #include "eloop.h" #include "drv_cfg.h"
@@ -47,6 +58,7 @@#include "lldp/l2_packet.h" #include "config.h" #include "lldp/states.h" +#include "messages.h" static void event_if_decode_rta (int type,struct rtattr *rta);
@@ -55,6 +67,32 @@ static void event_if_decode_rta(int type, struct rtattr *rta);static char *device_name =NULL ;static int link_status =0 ; +static struct nla_policy ifla_vf_policy[IFLA_VF_MAX +1 ] = +{ + [IFLA_VF_MAC ] = { .minlen =sizeof (struct ifla_vf_mac ), + .maxlen =sizeof (struct ifla_vf_mac )}, + [IFLA_VF_VLAN ] = { .minlen =sizeof (struct ifla_vf_vlan ), + .maxlen =sizeof (struct ifla_vf_vlan )}, +}; + +static struct nla_policy ifla_vf_ports_policy[IFLA_VF_PORT_MAX +1 ] = +{ + [IFLA_VF_PORT ] = { .type =NLA_NESTED }, +}; + +static struct nla_policy ifla_port_policy[IFLA_PORT_MAX +1 ] = +{ + [IFLA_PORT_VF ] = { .type =NLA_U32 }, + [IFLA_PORT_PROFILE ] = { .type =NLA_STRING }, + [IFLA_PORT_VSI_TYPE ] = { .minlen =sizeof (struct ifla_port_vsi ) }, + [IFLA_PORT_INSTANCE_UUID ] = { .minlen =PORT_UUID_MAX , + .maxlen =PORT_UUID_MAX , }, + [IFLA_PORT_HOST_UUID ] = { .minlen =PORT_UUID_MAX , + .maxlen =PORT_UUID_MAX , }, + [IFLA_PORT_REQUEST ] = { .type =NLA_U8 }, + [IFLA_PORT_RESPONSE ] = { .type =NLA_U16 }, +}; +static void event_if_decode_rta (int type,struct rtattr *rta) {
@@ -220,15 +258,513 @@ static void event_if_decode_nlmsg(int route_type, void *data, int len) } } -static void event_if_process_recvmsg (struct nlmsghdr *nlmsg) { - -/* print out details */ +LLDPAD_DBG ("%s:%s: nlmsg_type: %d" , __FILE__, __FUNCTION__, nlmsg->nlmsg_type);event_if_decode_nlmsg (nlmsg->nlmsg_type,NLMSG_DATA (nlmsg),NLMSG_PAYLOAD (nlmsg,0 )); } +static int event_if_parse_getmsg (struct nlmsghdr *nlh,int *ifindex, +char *ifname) +{ +struct nlattr *tb[IFLA_MAX +1 ]; +struct ifinfomsg *ifinfo; + +if (nlmsg_parse (nlh,sizeof (struct ifinfomsg ), + (struct nlattr **)&tb,IFLA_MAX ,NULL )) { +LLDPAD_ERR ("Error parsing GETLINK request..." ); +return -EINVAL ; + } + +if (tb[IFLA_IFNAME ]) { + ifname = (char *)RTA_DATA (tb[IFLA_IFNAME ]); +LLDPAD_DBG ("IFLA_IFNAME=%s" , ifname); + }else { + ifinfo = (struct ifinfomsg *)NLMSG_DATA (nlh); + *ifindex = ifinfo->ifi_index; +LLDPAD_DBG ("interface index: %d" , ifinfo->ifi_index); + } + +return 0 ; +} + +static int event_if_parse_setmsg (struct nlmsghdr *nlh) +{ +struct nlattr *tb[IFLA_MAX +1 ], + *tb3[IFLA_PORT_MAX +1 ], + *tb_vfinfo[IFLA_VF_MAX +1 ], + *tb_vfinfo_list; +struct vsi_profile *profile, *p; +struct ifinfomsg *ifinfo; +char *ifname; +int rem; + + profile =malloc (sizeof (struct vsi_profile )); +if (!profile) +return -ENOMEM ; +memset (profile,0 ,sizeof (struct vsi_profile )); + +if (nlmsg_parse (nlh,sizeof (struct ifinfomsg ), + (struct nlattr **)&tb,IFLA_MAX ,NULL )) { +LLDPAD_ERR ("Error parsing request...\n" ); +return -EINVAL ; + } + +LLDPAD_DBG ("%s(%d): nlmsg_len %i" , __FILE__, __LINE__, nlh->nlmsg_len); + +if (tb[IFLA_IFNAME ]) { + ifname = (char *)RTA_DATA (tb[IFLA_IFNAME ]); +LLDPAD_DBG ("IFLA_IFNAME=%s" , ifname); + }else { + ifinfo = (struct ifinfomsg *)NLMSG_DATA (nlh); +LLDPAD_DBG ("interface index: %d" , ifinfo->ifi_index); + } + +if (!tb[IFLA_VFINFO_LIST ]) { +LLDPAD_ERR ("IFLA_VFINFO_LIST missing." ); +return -EINVAL ; + }else { +LLDPAD_DBG ("FOUND IFLA_VFINFO_LIST!" ); + } + +nla_for_each_nested (tb_vfinfo_list, tb[IFLA_VFINFO_LIST ], rem) { +if (nla_type (tb_vfinfo_list) !=IFLA_VF_INFO ) { +LLDPAD_ERR ("nested parsing of IFLA_VFINFO_LIST failed." ); +return -EINVAL ; + } + +if (nla_parse_nested (tb_vfinfo,IFLA_VF_MAX , tb_vfinfo_list, + ifla_vf_policy)) { +LLDPAD_ERR ("nested parsing of IFLA_VF_INFO failed." ); +return -EINVAL ; + } + } + +if (tb_vfinfo[IFLA_VF_MAC ]) { +struct ifla_vf_mac *mac =RTA_DATA (tb_vfinfo[IFLA_VF_MAC ]); +u8 *m = mac->mac; +LLDPAD_DBG ("IFLA_VF_MAC=%2x:%2x:%2x:%2x:%2x:%2x" , + m[0 ], m[1 ], m[2 ], m[3 ], m[4 ], m[5 ]); +memcpy (&profile->mac, m,ETH_ALEN ); + } + +if (tb_vfinfo[IFLA_VF_VLAN ]) { +struct ifla_vf_vlan *vlan =RTA_DATA (tb_vfinfo[IFLA_VF_VLAN ]); +LLDPAD_DBG ("IFLA_VF_VLAN=%d" , vlan->vlan); + profile->vlan = (u16 ) vlan->vlan; + } + +if (tb[IFLA_VF_PORTS ]) { +struct nlattr *tb_vf_ports; + +LLDPAD_DBG ("FOUND IFLA_VF_PORTS" ); + +nla_for_each_nested (tb_vf_ports, tb[IFLA_VF_PORTS ], rem) { + +LLDPAD_DBG ("ITERATING" ); + +if (nla_type (tb_vf_ports) !=IFLA_VF_PORT ) { +LLDPAD_DBG ("not a IFLA_VF_PORT. skipping" ); +continue ; + } + +if (nla_parse_nested (tb3,IFLA_PORT_MAX , tb_vf_ports, + ifla_port_policy)) { +LLDPAD_ERR ("nested parsing on level 2 failed." ); +return -EINVAL ; + } + +if (tb3[IFLA_PORT_VF ]) { +LLDPAD_DBG ("IFLA_PORT_VF=%d" , *(uint32_t *)(RTA_DATA (tb3[IFLA_PORT_VF ]))); + } + +if (tb3[IFLA_PORT_PROFILE ]) { +LLDPAD_DBG ("IFLA_PORT_PROFILE=%s" , (char *)RTA_DATA (tb3[IFLA_PORT_PROFILE ])); + } + +if (tb3[IFLA_PORT_VSI_TYPE ]) { +struct ifla_port_vsi *pvsi; +int tid =0 ; + + pvsi = (struct ifla_port_vsi *)RTA_DATA (tb3[IFLA_PORT_VSI_TYPE ]); + tid = pvsi->vsi_type_id[2 ] <<16 | + pvsi->vsi_type_id[1 ] <<8 | + pvsi->vsi_type_id[0 ]; + +LLDPAD_DBG ("mgr_id : %d" , pvsi->vsi_mgr_id); +LLDPAD_DBG ("type_id : %d" , tid); +LLDPAD_DBG ("type_version : %d" , pvsi->vsi_type_version); + + profile->mgrid = pvsi->vsi_mgr_id; + profile->id = tid; + profile->version = pvsi->vsi_type_version; + } + +if (tb3[IFLA_PORT_INSTANCE_UUID ]) { +int i; +unsigned char *uuid; + uuid = (unsigned char *)RTA_DATA (tb3[IFLA_PORT_INSTANCE_UUID ]); + +char instance[INSTANCE_STRLEN +2 ]; +instance2str (uuid, instance,sizeof (instance)); +LLDPAD_DBG ("IFLA_PORT_INSTANCE_UUID=%s" , &instance[0 ]); + +memcpy (&profile->instance, +RTA_DATA (tb3[IFLA_PORT_INSTANCE_UUID ]),16 ); + } + +if (tb3[IFLA_PORT_REQUEST ]) { +LLDPAD_DBG ("IFLA_PORT_REQUEST=%d" , + *(uint8_t *)RTA_DATA (tb3[IFLA_PORT_REQUEST ])); + profile->mode = *(uint8_t *)RTA_DATA (tb3[IFLA_PORT_REQUEST ]); + } + +if (tb3[IFLA_PORT_RESPONSE ]) { +LLDPAD_DBG ("IFLA_PORT_RESPONSE=%d" , + *(uint16_t *)RTA_DATA (tb3[IFLA_PORT_RESPONSE ])); + profile->response = *(uint16_t *)RTA_DATA (tb3[IFLA_PORT_RESPONSE ]); + } + } + } + +if (ifname) { +struct port *port =port_find_by_name (ifname); + +if (port) { + profile->port = port; + }else { +LLDPAD_ERR ("%s(%i): Could not find port for %s" , __func__, + __LINE__, ifname); +return -EEXIST ; + } + } + + p =vdp_add_profile (profile); + +if (!p) { +free (profile); +return -EINVAL ; + } + +vdp_somethingChangedLocal (profile,VDP_PROFILE_REQ ); +vdp_vsi_sm_station (p); + +return 0 ; +} + +static void event_if_parseResponseMsg (struct nlmsghdr *nlh) +{ +struct nlattr *tb[IFLA_MAX +1 ], + *tb2[IFLA_VF_PORT_MAX +1 ], + *tb3[IFLA_PORT_MAX +1 ]; + +if (nlmsg_parse (nlh,sizeof (struct ifinfomsg ), + (struct nlattr **)&tb,IFLA_MAX ,NULL )) { +LLDPAD_ERR ("Error parsing netlink response..." ); +return ; + } + +if (tb[IFLA_IFNAME ]) { +LLDPAD_DBG ("IFLA_IFNAME=%s" , (char *)RTA_DATA (tb[IFLA_IFNAME ])); + }else { +struct ifinfomsg *ifinfo = (struct ifinfomsg *)NLMSG_DATA (nlh); +LLDPAD_DBG ("interface index: %d" , ifinfo->ifi_index); + } + +if (tb[IFLA_VF_PORTS ]) { +if (nla_parse_nested (tb2,IFLA_VF_PORT_MAX , tb[IFLA_VF_PORTS ], + ifla_vf_ports_policy)) { +LLDPAD_ERR ("nested parsing on level 1 failed." ); +return ; + } + +if (tb2[IFLA_VF_PORT ]) { +if (nla_parse_nested (tb3,IFLA_PORT_MAX , tb2[IFLA_VF_PORT ], + ifla_port_policy)) { +LLDPAD_ERR ("nested parsing on level 2 failed." ); +return ; + } + +if (tb3[IFLA_PORT_VF ]) { +LLDPAD_DBG ("IFLA_PORT_VF=%d" , *(uint32_t *)(RTA_DATA (tb3[IFLA_PORT_VF ]))); + } + +if (tb3[IFLA_PORT_PROFILE ]) { +LLDPAD_DBG ("IFLA_PORT_PROFILE=%s" , (char *)RTA_DATA (tb3[IFLA_PORT_PROFILE ])); + } + +if (tb3[IFLA_PORT_VSI_TYPE ]) { +struct ifla_port_vsi *pvsi; +int tid =0 ; + pvsi = (struct ifla_port_vsi *)RTA_DATA (tb3[IFLA_PORT_VSI_TYPE ]); + tid = pvsi->vsi_type_id[2 ] <<16 | + pvsi->vsi_type_id[1 ] <<8 | + pvsi->vsi_type_id[0 ]; +LLDPAD_DBG ("mgr_id : %d" +"type_id : %d" +"type_version : %d" , + pvsi->vsi_mgr_id, + tid, + pvsi->vsi_type_version); + } + +if (tb3[IFLA_PORT_INSTANCE_UUID ]) { +int i; +unsigned char *uuid; + uuid = (unsigned char *)RTA_DATA (tb3[IFLA_PORT_INSTANCE_UUID ]); + +char instance[INSTANCE_STRLEN +2 ]; +instance2str (uuid, instance,sizeof (instance)); +LLDPAD_DBG ("IFLA_PORT_INSTANCE_UUID=%s" , &instance[0 ]); + } + +if (tb3[IFLA_PORT_REQUEST ]) { +LLDPAD_DBG ("IFLA_PORT_REQUEST=%d" , + *(uint8_t *)RTA_DATA (tb3[IFLA_PORT_REQUEST ])); + } + +if (tb3[IFLA_PORT_RESPONSE ]) { +LLDPAD_DBG ("IFLA_PORT_RESPONSE=%d" , + *(uint16_t *)RTA_DATA (tb3[IFLA_PORT_RESPONSE ])); + } + } + } +} + +struct nl_msg *event_if_constructResponse (struct nlmsghdr *nlh,int ifindex) +{ +struct nl_msg *nl_msg; +struct nlattr *vf_ports =NULL , *vf_port; +struct ifinfomsg ifinfo; +struct vdp_data *vd; +uint32_t pid = nlh->nlmsg_pid; +uint32_t seq = nlh->nlmsg_seq; +char *ifname =malloc (IFNAMSIZ ); +struct vsi_profile *p; + + nl_msg =nlmsg_alloc (); + +if (!nl_msg) { +LLDPAD_ERR ("%s(%i): Unable to allocate netlink message !" , __func__, __LINE__); +return NULL ; + } + +if (!if_indextoname (ifindex, ifname)) { +LLDPAD_ERR ("%s(%i): No name found for interface with index %i !" , __func__, __LINE__, + ifindex); + } + + vd =vdp_data (ifname); +if (!vd) { +LLDPAD_ERR ("%s(%i): Could not find vdp_data for %s !" , __func__, __LINE__, + ifname); +return NULL ; + } + +if (nlmsg_put (nl_msg, pid, seq,NLMSG_DONE ,0 ,0 ) ==NULL ) + goto err_exit; + + ifinfo.ifi_index = ifindex; + +if (nlmsg_append (nl_msg, &ifinfo,sizeof (ifinfo),NLMSG_ALIGNTO ) <0 ) + goto err_exit; + + vf_ports =nla_nest_start (nl_msg,IFLA_VF_PORTS ); + +if (!vf_ports) + goto err_exit; + +/* loop over all existing profiles on this interface and +* put them into the nested IFLA_VF_PORT structure */ + LIST_FOREACH(p, &vd->profile_head, profile) { +if (p) { +vdp_print_profile (p); + + vf_port =nla_nest_start (nl_msg,IFLA_VF_PORT ); + +if (!vf_port) + goto err_exit; + +if (nla_put (nl_msg,IFLA_PORT_INSTANCE_UUID ,16 , p->instance) <0 ) + goto err_exit; + +if (nla_put_u32 (nl_msg,IFLA_PORT_VF ,PORT_SELF_VF ) <0 ) + goto err_exit; + +if (p->mode == p->state) { +if (nla_put_u16 (nl_msg,IFLA_PORT_RESPONSE , +PORT_VDP_RESPONSE_SUCCESS ) <0 ) + goto err_exit; + }else { +if (p->state ==VSI_EXIT ) { +if (p->response >PORT_VDP_RESPONSE_SUCCESS ) { +if (nla_put_u16 (nl_msg,IFLA_PORT_RESPONSE , p->response) <0 ) + goto err_exit; + }else { +if (nla_put_u16 (nl_msg,IFLA_PORT_RESPONSE , +PORT_VDP_RESPONSE_INSUFFICIENT_RESOURCES ) <0 ) + goto err_exit; + } + } + } + +nla_nest_end (nl_msg, vf_port); + } + } + +if (vf_ports) +nla_nest_end (nl_msg, vf_ports); + +return nl_msg; + +err_exit: +nlmsg_free (nl_msg); + +return NULL ; +} + +struct nl_msg *event_if_simpleResponse (uint32_t pid,uint32_t seq,int err) +{ +struct nl_msg *nl_msg =nlmsg_alloc (); +struct nlmsgerr nlmsgerr; + +memset (&nlmsgerr,0x0 ,sizeof (nlmsgerr)); + + nlmsgerr.error = err; +LLDPAD_DBG ("RESPONSE error code: %d" ,err); + +if (nlmsg_put (nl_msg, pid, seq,NLMSG_ERROR ,0 ,0 ) ==NULL ) + goto err_exit; + +if (nlmsg_append (nl_msg, &nlmsgerr,sizeof (nlmsgerr),NLMSG_ALIGNTO ) <0 ) + goto err_exit; + +return nl_msg; + +err_exit: +nlmsg_free (nl_msg); + +return NULL ; +} + +static void event_iface_receive_user_space (int sock,void *eloop_ctx,void *sock_ctx) +{ +struct nlmsghdr *nlh; +struct nl_msg *nl_msg; +struct msghdr msg; +struct sockaddr_nl dest_addr; +struct iovec iov; +int result; +int err; +int ifindex =0 ; +char *ifname =NULL ; + + nlh = (struct nlmsghdr *)calloc (1 , +NLMSG_SPACE (MAX_PAYLOAD )); +if (!nlh) { +LLDPAD_ERR ("%s(%i): could not allocate nlh !" , __func__, + __LINE__); +return ; + } +memset (nlh,0 ,NLMSG_SPACE (MAX_PAYLOAD )); + +memset (&dest_addr,0 ,sizeof (dest_addr)); + iov.iov_base = (void *)nlh; + iov.iov_len =NLMSG_SPACE (MAX_PAYLOAD ); + msg.msg_name = (void *)&dest_addr; + msg.msg_namelen =sizeof (dest_addr); + msg.msg_iov = &iov; + msg.msg_iovlen =1 ; + msg.msg_control =NULL ; + msg.msg_controllen =0 ; + msg.msg_flags =0 ; + +LLDPAD_DBG ("Waiting for message" ); + result =recvmsg (sock, &msg,MSG_DONTWAIT ); + +LLDPAD_DBG ("%s(%i): " , __func__, __LINE__); +LLDPAD_DBG ("recvmsg received %d bytes" , result); + +if (result <0 ) { +LLDPAD_ERR ("Error receiving from netlink socket : %s" ,strerror (errno)); + } + +LLDPAD_DBG ("dest_addr.nl_pid: %d" , dest_addr.nl_pid); +LLDPAD_DBG ("nlh.nl_pid: %d" , nlh->nlmsg_pid); +LLDPAD_DBG ("nlh_type: %d" , nlh->nlmsg_type); +LLDPAD_DBG ("nlh_seq: 0x%x" , nlh->nlmsg_seq); +LLDPAD_DBG ("nlh_len: 0x%x" , nlh->nlmsg_len); + +switch (nlh->nlmsg_type) { +case RTM_SETLINK : +LLDPAD_DBG ("RTM_SETLINK" ); + + err =event_if_parse_setmsg (nlh); + +/* send simple response wether profile was accepted +* or not */ + nl_msg =event_if_simpleResponse (nlh->nlmsg_pid, + nlh->nlmsg_seq, + err); + nlh =nlmsg_hdr (nl_msg); +break ; +case RTM_GETLINK : +LLDPAD_DBG ("RTM_GETLINK" ); + + err =event_if_parse_getmsg (nlh, &ifindex, ifname); + +if (err) { + nl_msg =event_if_simpleResponse (nlh->nlmsg_pid, + nlh->nlmsg_seq, + err); + }else if (ifname) { + ifindex =if_nametoindex (ifname); +LLDPAD_DBG ("%s(%i): ifname %s (%d)" , __func__, + __LINE__, ifname, ifindex); + }else { + ifname =malloc (IFNAMSIZ ); +LLDPAD_DBG ("%s(%i): ifindex %i" , __func__, + __LINE__, ifindex); + } + + nl_msg =event_if_constructResponse (nlh, ifindex); + +if (!nl_msg) { +LLDPAD_ERR ("%s(%i): Unable to construct response !" , + __func__, __LINE__); + goto out_err; + } + + nlh =nlmsg_hdr (nl_msg); + +LLDPAD_DBG ("RESPONSE:" ); + +event_if_parseResponseMsg (nlh); + +break ; + } + + iov.iov_base = (void *)nlh; + iov.iov_len = nlh->nlmsg_len; + + msg.msg_name = (void *)&dest_addr; + msg.msg_namelen =sizeof (dest_addr); + msg.msg_iov = &iov; + msg.msg_iovlen =1 ; + + result =sendmsg (sock, &msg,0 ); + +if (result <0 ) { +LLDPAD_ERR ("Error sending on netlink socket (%s) !" ,strerror (errno)); + }else { +LLDPAD_DBG ("Sent %d bytes !" ,result); + } + +out_err: +free (nlh); +} +static void event_iface_receive (int sock,void *eloop_ctx,void *sock_ctx) {struct nlmsghdr *nlh;
@@ -236,12 +772,14 @@ static void event_iface_receive(int sock, void *eloop_ctx, void *sock_ctx)char buf[MAX_MSG_SIZE ];socklen_t fromlen =sizeof (dest_addr);int result; - + result =recvfrom (sock, buf,sizeof (buf),MSG_DONTWAIT , (struct sockaddr *) &dest_addr, &fromlen); +LLDPAD_DBG ("%s:%s: result from receive: %d" , __FILE__, __FUNCTION__, result); +if (result <0 ) { -perror ("recvfrom(Event interface)" ); +LLDPAD_ERR ("recvfrom(event interface): %s" ,strerror (errno));if ((errno ==ENOBUFS ) || (errno ==EAGAIN ))eloop_register_timeout (INI_TIMER ,0 , scan_port,NULL ,NULL );
@@ -250,10 +788,15 @@ static void event_iface_receive(int sock, void *eloop_ctx, void *sock_ctx)TRACE ("PRINT BUF info.\n" ) - device_name =NULL ; - link_status =IF_OPER_UNKNOWN ; - nlh = (struct nlmsghdr *)buf; -event_if_process_recvmsg (nlh); + /* Separate handler for kernel messages from userspace messages*/ +LLDPAD_DBG ("%s:%s: dest_addr.nl_pid: %d" , __FILE__, __FUNCTION__, dest_addr.nl_pid); + +if (dest_addr.nl_pid ==0 ) { + device_name =NULL ; + link_status =IF_OPER_UNKNOWN ; + nlh = (struct nlmsghdr *)buf; +event_if_process_recvmsg (nlh); + } }int event_iface_init ()
@@ -261,7 +804,7 @@ int event_iface_init()int fd;int rcv_size =MAX_MSG_SIZE ;struct sockaddr_nl snl; - +fprintf (stderr,"%s:%s:%d\n" , __FILE__, __FUNCTION__, __LINE__); fd =socket (PF_NETLINK ,SOCK_RAW ,NETLINK_ROUTE );if (fd <0 )
@@ -282,6 +825,39 @@ int event_iface_init() }eloop_register_read_sock (fd, event_iface_receive,NULL ,NULL ); + +return 0 ; +} + +int event_iface_init_user_space () +{ +int fd; +int rcv_size =MAX_MSG_SIZE ; +struct sockaddr_nl snl; + + fd =socket (PF_NETLINK ,SOCK_RAW ,NETLINK_ROUTE ); + +if (fd <0 ) +return fd; + +if (setsockopt (fd,SOL_SOCKET ,SO_RCVBUF , &rcv_size,sizeof (int )) <0 ) { +close (fd); +return -EIO ; + } + +memset ((void *)&snl,0 ,sizeof (struct sockaddr_nl )); + snl.nl_family =AF_NETLINK ; + snl.nl_pid =getpid ();/* self pid */ + snl.nl_groups =0 ; + +if (bind (fd, (struct sockaddr *)&snl,sizeof (struct sockaddr_nl )) <0 ) { +close (fd); +LLDPAD_ERR ("Error binding to netlink socket (%s) !" ,strerror (errno)); +return -EIO ; + } + +eloop_register_read_sock (fd, event_iface_receive_user_space,NULL ,NULL ); +return 0 ; }
include/event_iface.h +1 -0
@@ -29,6 +29,7 @@#define _EVENT_IFACE_H_int event_iface_init (void ); +int event_iface_init_user_space (void );int event_iface_deinit (void );int oper_add_device (char *device_name);
include/lldp_vdp.h +2 -0
@@ -134,6 +134,8 @@ struct vdp_data *vdp_data(char *ifname);struct packed_tlv *vdp_gettlv (struct vdp_data *vd,struct vsi_profile *profile);void vdp_vsi_sm_station (struct vsi_profile *profile);struct vsi_profile *vdp_add_profile (struct vsi_profile *profile); +void vdp_somethingChangedLocal (struct vsi_profile *profile,int mode); +void vdp_print_profile (struct vsi_profile *profile);#define MAC_ADDR_STRLEN 18#define INSTANCE_STRLEN 32
lldp_vdp.c +1 -1
@@ -105,7 +105,7 @@ static void vdp_free_data(struct vdp_user_data *ud)* prints the contents of a profile first to a string using the PRINT_PROFILE * macro, and then to the screen. Used for debug purposes. */ -static inline void vdp_print_profile (struct vsi_profile *profile) +void vdp_print_profile (struct vsi_profile *profile) {LLDPAD_DBG ("profile:\n" );
lldpad.c +10 -0
@@ -374,6 +374,16 @@ int main(int argc, char *argv[])exit (1 ); } +/* setup event netlink interface for user space processes. +* This needs to be setup first to ensure it gets lldpads +* pid as netlink address. +*/ +if (event_iface_init_user_space () <0 ) { +log_message (MSG_ERR_SERVICE_START_FAILURE , +"%s" ,"failed to register user space event interface" ); +exit (1 ); + } +init_modules ("" );
Signature · 1 line
1.7.1
PATCH 9/9 do not use macv[tap/lan] interfaces as ports
In reply to Jens OsterkampAt startup lldpad walks through all network interfaces in the system and creates internal data structures for them. Some interfaces as e.g. vlan and wlan are skipped in the walkthrough, some have to be treated special (e.g. bond devices).
This patch adds macvtap and macvlan interfaces to the list of devices that are skipped as we do not want to send out EVB/ECP frames on them.
--- config.c | 2 + include/lldp_util.h | 1 + lldp_util.c | 90 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 93 insertions(+), 0 deletions(-)
config.c +2 -0
@@ -365,6 +365,8 @@ void init_ports(void) p->if_name); }else if (is_vlan (p->if_name)) { ; + }else if (is_macvtap (p->if_name)) { + ; }else if (is_bridge (p->if_name)) { ;/* ignore bridge device */ }else if (check_link_status (p->if_name)) {
include/lldp_util.h +1 -0
@@ -40,6 +40,7 @@ int is_bridge(const char *ifname);int is_vlan (const char *ifname);int is_vlan_capable (const char *ifname);int is_wlan (const char *ifname); +int is_macvtap (const char *ifname);int is_valid_mac (const u8 *mac);int is_san_mac (u8 *addr);int is_ether (const char *ifname);
lldp_util.c +90 -0
114 lines not on this page · raw message
Signature · 1 line
1.7.1