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.
The patches have been rebased to lldpad 0.9.38 and still contain code to log low-level protocol activity more verbosely than necessary.
In comparison to the last posted series, several changes have been made:
- all EVB TLV patches have been folded into one
- ECP and VDP implementation now only consists of 3 patches: ECP, VDP and VDP commandline interface
- the protocol specific ecp structure has been moved away from the general port structure
- the non-standard ECP_TX_IDLE state has been removed from the ECP TX state machine which causes ecp frames to be sent out immediately to allow sequence synchronization
- VDP subtype has changed from 0 to 2
- some network byte order in the VSI tlv have been fixed
- vdp config variables are now saved in subsection "vdp" under the interface in lldpad.conf
- some compiler warnings have been fixed
- many other small bug fixes
For more information about lldpad take a look at
http://sourceforge.net/projects/e1000/files/DCB%20Tools/lldpad/
Please review and comment.
Thanks !
Jens
PATCH 1/10 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/10 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 | 658 +++++++++++++++++++++++++++++++++++++++++++++++ lldp_evb_clif.c | 226 ++++++++++++++++ lldp_evb_cmds.c | 512 ++++++++++++++++++++++++++++++++++++ lldpad.c | 2 + lldptool.c | 2 + 11 files changed, 1588 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 4096 +#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 +658 -0
658 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 +512 -0
512 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
Re: [E1000-eedc] [PATCH 02/10] implementation of IEEE 802.1Qbg in lldpad, part 1
Quoted 428 lines · Jens Osterkamp
This 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.
Signed-off-by Jens Osterkamp <[email protected]>--- 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 | 658 +++++++++++++++++++++++++++++++++++++++++++++++ lldp_evb_clif.c | 226 ++++++++++++++++ lldp_evb_cmds.c | 512 ++++++++++++++++++++++++++++++++++++ lldpad.c | 2 + lldptool.c | 2 + 11 files changed, 1588 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.cMakefile.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.hinclude/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 4096 +#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@@ -0,0 +1,80 @@ +/******************************************************************************* + +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_H +#define _LLDP_EVB_H + +#include "lldp_mod.h" + +#define LLDP_MOD_EVB OUI_IEEE_8021Qbg +#define LLDP_OUI_SUBTYPE { 0x00, 0x1b, 0x3f, 0x00 } + +typedef enum { +EVB_OFFER_CAPABILITIES =0 , +EVB_CONFIGURE , +EVB_CONFIRMATION +}evb_state ; + +struct tlv_info_evb { +u8 oui[3 ]; +u8 sub; +/* supported forwarding mode */ +u8 smode; +/* supported capabilities */ +u8 scap; +/* currently configured forwarding mode */ +u8 cmode; +/* currently configured capabilities */ +u8 ccap; +/* supported no. of vsi */ +u16 svsi; +/* currently configured no. of vsi */ +u16 cvsi; +/* retransmission exponent */ +u8 rte; +} __attribute__ ((__packed__ )); + +struct evb_data { +char ifname[IFNAMSIZ ]; +struct unpacked_tlv *evb; +struct tlv_info_evb *tie; +/* local policy */ +struct tlv_info_evb *policy; +int state; +LIST_ENTRY (evb_data) entry; +}; + +struct evb_user_data { + LIST_HEAD(evb_head, evb_data) head; +}; + +struct lldp_module *evb_register (void ); +void evb_unregister (struct lldp_module *mod); +struct packed_tlv *evb_gettlv (struct port *port); +void evb_ifdown (char *); +void evb_ifup (char *); +struct evb_data *evb_data (char *ifname); + +#endif /* _LLDP_EVB_H */ include/lldp_evb_clif.h new file +51
-0@@ -0,0 +1,51 @@ +/******************************************************************************* + +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_CLIF_H +#define _LLDP_EVB_CLIF_H + +struct lldp_module *evb_cli_register (void ); +void evb_cli_unregister (struct lldp_module *); +int evb_print_tlv (u32 ,u16 ,char *); + +#define EVB_BUF_SIZE 256 + +#define ARG_EVB_FORWARDING_MODE "fmode" + +#define VAL_EVB_FMODE_BRIDGE "bridge" +#define VAL_EVB_FMODE_REFLECTIVE_RELAY "reflectiverelay" + +#define ARG_EVB_CAPABILITIES "capabilities" + +#define VAL_EVB_CAPA_RTE "rte" +#define VAL_EVB_CAPA_ECP "ecp" +#define VAL_EVB_CAPA_VDP "vdp" +#define VAL_EVB_CAPA_NONE "none" + +#define ARG_EVB_VSIS "vsis" + +#define ARG_EVB_RTE "rte" + +#endif 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 +102
-0@@ -0,0 +1,658 @@ +/******************************************************************************* + +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". + +*******************************************************************************/ + +#include <net/if.h> +#include <sys/queue.h> +#include <sys/socket.h> +#include <sys/ioctl.h> +#include <sys/utsname.h> +#include <linux/if_bridge.h> +#include <string.h> +#include "lldp.h" +#include "lldp_evb.h" +#include "messages.h" +#include "config.h" +#include "common.h" +#include "lldp_mand_clif.h" +#include "lldp_evb_clif.h" +#include "lldp_evb_cmds.h" + +extern struct lldp_head lldp_head; + +struct evb_data *evb_data (char *ifname) +{ +struct evb_user_data *ud; +struct evb_data *ed =NULL ; + + ud =find_module_user_data_by_if (ifname, &lldp_head,LLDP_MOD_EVB ); +if (ud) { + LIST_FOREACH(ed, &ud->head, entry) { +if (!strncmp (ifname, ed->ifname,IFNAMSIZ )) +return ed; + } + } +return NULL ; +} + +static void evb_print_tlvinfo (struct tlv_info_evb *tie) +{ +printf ("%s(%i): supported forwarding mode: %02x\n" , __FILE__, __LINE__, tie->smode); +printf ("%s(%i): configured forwarding mode: %02x\n" , __FILE__, __LINE__, tie->cmode); +printf ("%s(%i): supported capabilities: %02x\n" , __FILE__, __LINE__, tie->scap); +printf ("%s(%i): configured capabilities: %02x\n" , __FILE__, __LINE__, tie->ccap); +printf ("%s(%i): supported no. of vsis: %04i\n" , __FILE__, __LINE__, tie->svsi); +printf ("%s(%i): configured no. of vsis: %04i\n" , __FILE__, __LINE__, tie->cvsi); +printf ("%s(%i): rte: %02i\n\n" , __FILE__, __LINE__, tie->rte); +} + +/* +* evb_bld_cfg_tlv - build the EVB TLV +* @ed: the evb data struct +* +* Returns 0 on success +*/ +static int evb_bld_cfg_tlv (struct evb_data *ed) +{ +int rc =0 ; +int i; +struct unpacked_tlv *tlv =NULL ; + +/* free ed->evb if it exists */ +FREE_UNPKD_TLV (ed, evb); + +if (!is_tlv_txenabled (ed->ifname,TLVID_8021Qbg (LLDP_EVB_SUBTYPE ))) { +fprintf (stderr,"%s:%s:EVB tx is currently disabled !\n" , + __func__, ed->ifname); + rc =EINVAL ; + goto out_err; + } + + tlv =create_tlv (); +if (!tlv) + goto out_err; + + tlv->type =ORG_SPECIFIC_TLV ; + tlv->length =sizeof (struct tlv_info_evb ); + tlv->info = (u8 *)malloc (tlv->length); +if (!tlv->info) { +free (tlv); + tlv =NULL ; + rc =ENOMEM ;
lldp_evb.c line 112
Quoted 10 lines
lldp_evb.c new file +10
-0+ goto out_err; + } +memcpy (tlv->info, ed->tie, tlv->length); + +printf ("### %s:type %i, length %i, info " , __func__, tlv->type, tlv->length); + +for (i=0 ; i < tlv->length; i++) { +printf ("%02x " , tlv->info[i]); + } +
Remove the extra braces around the for statement. Granted the rest of lldpad may not follow a consistent coding style but lets try going forward and hopefully I get around to lldpad soon.
lldp_evb.c line 124
Quoted 12 lines
lldp_evb.c new file +12
-0+printf ("\n" ); + + ed->evb = tlv; +out_err: +return rc; +} + +static void evb_free_tlv (struct evb_data *ed) +{ +if (ed) { +FREE_UNPKD_TLV (ed, evb); + }
Same here extra braces.
lldp_evb.c line 137
Quoted 13 lines
lldp_evb.c new file +13
-0+} + +/* evb_init_cfg_tlv: +* +* fill up tlv_info_evb structure with reasonable info +*/ +static int evb_init_cfg_tlv (struct evb_data *ed) +{ +char arg_path[EVB_BUF_SIZE ]; +char *param; + +/* load policy from config */ + ed->policy = (struct tlv_info_evb *)calloc (1 ,sizeof (struct tlv_info_evb ));
Use malloc instead of callod() of one.
Quoted 122 lines
lldp_evb.c new file +122
-0+ +if (!ed->policy) +return ENOMEM ; + +/* set defaults */ +hton24 (ed->policy->oui,LLDP_MOD_EVB ); + ed->policy->smode =LLDP_EVB_CAPABILITY_FORWARD_STANDARD ; + ed->policy->scap =0 ; + ed->policy->cmode =0 ; + ed->policy->ccap =0 ; + ed->policy->svsi =0 /*LLDP_EVB_DEFAULT_SVSI*/ ; + ed->policy->rte =0 /*LLDP_EVB_DEFAULT_RTE*/ ; + +/* pull forwarding mode into policy */ +snprintf (arg_path,sizeof (arg_path),"%s%08x.fmode" , +TLVID_PREFIX ,TLVID_8021Qbg (LLDP_EVB_SUBTYPE )); + +if (get_cfg (ed->ifname, arg_path, (void *) ¶m,CONFIG_TYPE_STRING )) { +printf ("%s:%s: loading EVB policy for forwarding mode failed, using default.\n" , + __func__, ed->ifname); + }else { +if (strcasestr (param,VAL_EVB_FMODE_BRIDGE )) { + ed->policy->smode =LLDP_EVB_CAPABILITY_FORWARD_STANDARD ; + } + +if (strcasestr (param,VAL_EVB_FMODE_REFLECTIVE_RELAY )) { + ed->policy->smode =LLDP_EVB_CAPABILITY_FORWARD_REFLECTIVE_RELAY ; + } + +printf ("%s:%s: policy param fmode = %s.\n" , __func__, ed->ifname, param); +printf ("%s:%s: policy param smode = %x.\n" , __func__, ed->ifname, ed->policy->smode); + } + +/* pull capabilities into policy */ +snprintf (arg_path,sizeof (arg_path),"%s%08x.capabilities" , +TLVID_PREFIX ,TLVID_8021Qbg (LLDP_EVB_SUBTYPE )); + +if (get_cfg (ed->ifname, arg_path, (void *) ¶m,CONFIG_TYPE_STRING )) { +printf ("%s:%s: loading EVB policy for capabilities failed, using default.\n" , + __func__, ed->ifname); + }else { +if (strcasestr (param,VAL_EVB_CAPA_RTE )) { + ed->policy->scap |=LLDP_EVB_CAPABILITY_PROTOCOL_RTE ; + } + +if (strcasestr (param,VAL_EVB_CAPA_ECP )) { + ed->policy->scap |=LLDP_EVB_CAPABILITY_PROTOCOL_ECP ; + } + +if (strcasestr (param,VAL_EVB_CAPA_VDP )) { + ed->policy->scap |=LLDP_EVB_CAPABILITY_PROTOCOL_VDP ; + } + +printf ("%s:%s: policy param capabilities = %s.\n" , __func__, ed->ifname, param); +printf ("%s:%s: policy param scap = %x.\n" , __func__, ed->ifname, ed->policy->scap); + } + +/* pull rte into policy */ +snprintf (arg_path,sizeof (arg_path),"%s%08x.rte" , +TLVID_PREFIX ,TLVID_8021Qbg (LLDP_EVB_SUBTYPE )); + +if (get_cfg (ed->ifname, arg_path, (void *) ¶m,CONFIG_TYPE_STRING )) { +printf ("%s:%s: loading EVB policy for rte failed, using default.\n" , + __func__, ed->ifname); + }else { + ed->policy->rte =atoi (param); + +printf ("%s:%s: policy param rte = %s.\n" , __func__, ed->ifname, param); +printf ("%s:%s: policy param rte = %i.\n" , __func__, ed->ifname, ed->policy->rte); + } + +/* pull vsis into policy */ +snprintf (arg_path,sizeof (arg_path),"%s%08x.vsis" , +TLVID_PREFIX ,TLVID_8021Qbg (LLDP_EVB_SUBTYPE )); + +if (get_cfg (ed->ifname, arg_path, (void *) ¶m,CONFIG_TYPE_STRING )) { +printf ("%s:%s: loading EVB policy for vsis failed, using default.\n" , + __func__, ed->ifname); + }else { + ed->policy->svsi =atoi (param); + +printf ("%s:%s: policy param vsis = %s.\n" , __func__, ed->ifname, param); +printf ("%s:%s: policy param vsis = %i.\n" , __func__, ed->ifname, ed->policy->svsi); + } + +/* load last used EVB TLV ... */ + ed->tie = (struct tlv_info_evb *)calloc (1 ,sizeof (struct tlv_info_evb )); + +if (!ed->tie) +return ENOMEM ; + +if (get_config_tlvinfo_bin (ed->ifname,TLVID_8021Qbg (LLDP_EVB_SUBTYPE ), + (void *)ed->tie,sizeof (struct tlv_info_evb ))) { +printf ("%s:%s: loading last used EVB TLV failed, using default.\n" , + __func__, ed->ifname); +hton24 (ed->tie->oui,LLDP_MOD_EVB ); + ed->tie->smode =LLDP_EVB_CAPABILITY_FORWARD_REFLECTIVE_RELAY |LLDP_EVB_CAPABILITY_FORWARD_STANDARD ; + ed->tie->cmode =0x0 ; + ed->tie->scap =LLDP_EVB_CAPABILITY_PROTOCOL_RTE |LLDP_EVB_CAPABILITY_PROTOCOL_ECP + |LLDP_EVB_CAPABILITY_PROTOCOL_VDP ; + ed->tie->ccap =0x0 ; + ed->tie->svsi =LLDP_EVB_DEFAULT_SVSI ; + ed->tie->cvsi =0x0 ; + ed->tie->rte =LLDP_EVB_DEFAULT_RTE ; + }else { +printf ("%s(%i): loaded last used EVB TLV from file.\n" , __FILE__, __LINE__); + } + +return 0 ; +} + +static int evb_bld_tlv (struct evb_data *ed) +{ +int rc =0 ; + +if (!port_find_by_name (ed->ifname)) { + rc =EEXIST ; + goto out_err; + } + +if (!init_cfg ()) { + rc =ENOENT ;
lldp_evb.c line 269
Quoted 10 lines
lldp_evb.c new file +10
-0+ goto out_err; + } + +if (evb_bld_cfg_tlv (ed)) { +fprintf (stderr,"### %s:%s:evb_bld_cfg_tlv() failed\n" , + __func__, ed->ifname); + rc =EINVAL ; + goto out_err_destroy; + } +
Looks like you need 'return rc;' here.
This code falls through to destroy_cfg() if this is the case the 'goto out_err_destroy' is unneeded above. It really looks like a missed return code though
Quoted 51 lines
lldp_evb.c new file +51
-0+out_err_destroy: +destroy_cfg (); + +out_err: +return rc; +} + +static void evb_free_data (struct evb_user_data *ud) +{ +struct evb_data *ed; +if (ud) { +while (!LIST_EMPTY (&ud->head)) { + ed =LIST_FIRST (&ud->head); +LIST_REMOVE (ed, entry); +evb_free_tlv (ed); +free (ed); + } + } +} + +struct packed_tlv *evb_gettlv (struct port *port) +{ +int size; +struct evb_data *ed; +struct packed_tlv *ptlv =NULL ; + + ed =evb_data (port->ifname); +if (!ed) + goto out_err; + +evb_free_tlv (ed); + +if (evb_bld_tlv (ed)) { +fprintf (stderr,"### %s:%s evb_bld_tlv failed\n" , + __func__, port->ifname); + goto out_err; + } + + size =TLVSIZE (ed->evb); + +if (!size) + goto out_err; + + ptlv =create_ptlv (); +if (!ptlv) + goto out_err; + + ptlv->tlv =malloc (size); +if (!ptlv->tlv) + goto out_free; +
lldp_evb.c line 330
Quoted 10 lines
lldp_evb.c new file +10
-0+ ptlv->size =0 ; +PACK_TLV_AFTER (ed->evb, ptlv, size, out_free); +return ptlv; +out_free: +/* FIXME: free function returns pointer ? */ + ptlv =free_pkd_tlv (ptlv); +out_err: +fprintf (stderr,"### %s:%s: failed\n" , __func__, port->ifname); +return NULL ; +
remove extra line between return and closing brace.
Quoted 54 lines
lldp_evb.c new file +54
-0+} + +/* evb_check_and_fill +* +* checks values received in TLV and takes over some values +*/ +int evb_check_and_fill (struct evb_data *ed,struct tlv_info_evb *tie) +{ +/* sanity check of received data in tie */ +if ((tie->smode & (LLDP_EVB_CAPABILITY_FORWARD_STANDARD | +LLDP_EVB_CAPABILITY_FORWARD_REFLECTIVE_RELAY )) ==0 ) +return TLV_ERR ; + +if ((tie->svsi <0 ) || (tie->svsi >LLDP_EVB_DEFAULT_MAX_VSI )) +return TLV_ERR ; + +if ((tie->cvsi <0 ) || (tie->cvsi >LLDP_EVB_DEFAULT_MAX_VSI )) +return TLV_ERR ; + +/* check bridge capabilities against local policy*/ +/* if bridge supports RR and we support it as well, request it +* by setting smode in tlv to be sent out (ed->tie->smode) */ +if ( (tie->smode & ed->policy->smode) == +LLDP_EVB_CAPABILITY_FORWARD_REFLECTIVE_RELAY ) { + ed->tie->smode =LLDP_EVB_CAPABILITY_FORWARD_REFLECTIVE_RELAY ; + }else { + ed->tie->smode =LLDP_EVB_CAPABILITY_FORWARD_STANDARD ; + } + +/* If both sides support RTE, set it */ +if ((tie->scap & ed->policy->scap) &LLDP_EVB_CAPABILITY_PROTOCOL_RTE ) + ed->tie->scap |=LLDP_EVB_CAPABILITY_PROTOCOL_RTE ; + +/* If both sides support ECP, set it */ +if ((tie->scap & ed->policy->scap) &LLDP_EVB_CAPABILITY_PROTOCOL_ECP ) + ed->tie->scap |=LLDP_EVB_CAPABILITY_PROTOCOL_ECP ; + +/* If both sides support VDP, set it */ +if ((tie->scap & ed->policy->scap) &LLDP_EVB_CAPABILITY_PROTOCOL_VDP ) + ed->tie->scap |=LLDP_EVB_CAPABILITY_PROTOCOL_VDP ; + +/* If supported caps include VDP take over min value of both */ +if (ed->tie->scap &LLDP_EVB_CAPABILITY_PROTOCOL_VDP ) + ed->tie->cvsi =MIN (ed->policy->svsi,tie->svsi); + +/* If both sides support RTE and value offer is > 0, set it */ +if ((ed->tie->scap &LLDP_EVB_CAPABILITY_PROTOCOL_RTE ) && + (tie->rte >0 ) && (ed->policy->rte >0 )) + ed->tie->rte =MAX (ed->policy->rte,tie->rte); + +if (set_config_tlvinfo_bin (ed->ifname,TLVID_8021Qbg (LLDP_EVB_SUBTYPE ), + (void *)ed->tie,sizeof (struct tlv_info_evb ))) { +printf ("%s(%i): error saving tlv_info_evb !\n" , __FILE__, __LINE__); + }else {
lldp_evb.c line 394
Quoted 10 lines
lldp_evb.c new file +10
-0+printf ("%s(%i): saved tlv_info_evb to config !\n" , __FILE__, __LINE__); + } + +/* maybe switch has already set the mode based on the saved info sent +* out on ifup */ + +if (tie->cmode == ed->tie->smode) { + ed->tie->cmode = tie->cmode; + } +
remove the unneeded braces in the if statements above.
lldp_evb.c line 403
Quoted 9 lines
lldp_evb.c new file +9
-0+/* only look at the mode for now +if (tie->ccap == ed->tie->ccap) { +ed->tie->ccap = tie->ccap; +} + +if (tie->cvsi == ed->tie->cvsi) { +ed->tie->cvsi = tie->cvsi; +} +*/
Why is this commented out? I will review the spec shortly, but please remind me. If its not needed remove it and add it later in a clean patch
Quoted 5 lines
lldp_evb.c new file +5
-0+ +return TLV_OK ; +} + +/* evb_compare
lldp_evb.c line 418
Quoted 10 lines
lldp_evb.c new file +10
-0+* +* compare our own and received tlv_info_evb +*/ +static int evb_compare (struct evb_data *ed,struct tlv_info_evb *tie) +{ +printf ("%s(%i): \n" , __func__, __LINE__); + +if ((ed->tie->cmode == tie->cmode)/* && +(ed->tie->ccap == tie->ccap) && +(ed->tie->cvsi == tie->cvsi)*/ )
Same here if its going to be commented out lets remove it for now.
Quoted 43 lines
lldp_evb.c new file +43
-0+return 0 ; + else + return 1; +} + +/* evb_statemachine: +* +* handle possible states during EVB capabilities exchange +* +* possible states: EVB_OFFER_CAPABILITIES +* EVB_CONFIGURE +* EVB_CONFIRMATION +*/ +static void evb_statemachine (struct evb_data *ed,struct tlv_info_evb *tie) +{ +switch (ed->state) { +case EVB_OFFER_CAPABILITIES : +/* waiting for valid packets to pour in +* if valid packet was received, +* - check parameters with what we have offered for this if, +* - fill structure with data, +* - enable local tx +* - switch to EVB_CONFIGURE +*/ +printf ("%s: state -> EVB_OFFER_CAPABILITIES\n" , __func__); +if (evb_check_and_fill (ed, tie) !=TLV_OK ) { +fprintf (stderr,"Invalid contents of EVB Cfg TLV !\n" ); +return ; + } +somethingChangedLocal (ed->ifname);/* trigger tx with new values */ + ed->state =EVB_CONFIGURE ; +break ; +case EVB_CONFIGURE : +/* we received a valid packet, if contents is same with our local settings +* we can switch state to EVB_CONFIRMATION.*/ +printf ("%s: state -> EVB_CONFIGURE\n" , __func__); +if (evb_compare (ed, tie)) { + ed->state=EVB_OFFER_CAPABILITIES ; + }else { +printf ("tlv_info_evb now equal !\n" ); + ed->state =EVB_CONFIRMATION ; + } +somethingChangedLocal (ed->ifname);
lldp_evb.c line 471
Quoted 10 lines
lldp_evb.c new file +10
-0+break ; +case EVB_CONFIRMATION : +/* we are already in confirmation and received a new packet with +* different parameters ? Check parameters. switch state back to +* EVB_CONFIGURE ? */ +printf ("%s: state -> EVB_CONFIRMATION\n" , __func__); +#if 0 +if (ed->tie->scap &LLDP_EVB_CAPABILITY_PROTOCOL_ECP ) +ecp_init (ed->ifname); +#endif
remove the #if 0/endif it is never used.
Quoted 75 lines
lldp_evb.c new file +75
-0+break ; +default : +fprintf (stderr,"EVB statemachine reached invalid state !\n" ); +break ; + } +} + +/* +* evb_rchange: process RX TLV LLDPDU +* +* TLV not consumed on error +*/ +static int evb_rchange (struct port *port,struct unpacked_tlv *tlv) +{ +int i; +struct evb_data *ed; +struct tlv_info_evb *tie = (struct tlv_info_evb *) tlv->info; +u8 oui_subtype[OUI_SUB_SIZE ] =LLDP_OUI_SUBTYPE ; + +if (!init_cfg ()) { +return SUBTYPE_INVALID ; + } + + ed =evb_data (port->ifname); + +if (!ed) +return SUBTYPE_INVALID ; + +if (tlv->type ==TYPE_127 ) { +/* check for length */ +if (tlv->length < (OUI_SUB_SIZE )) { +return TLV_ERR ; + } + +/* check for oui */ +if (memcmp (tlv->info, &oui_subtype,OUI_SUB_SIZE )) { +return SUBTYPE_INVALID ; + } + +/* disable rx if tx has been disabled by administrator */ +if (!is_tlv_txenabled (ed->ifname,TLVID_8021Qbg (LLDP_EVB_SUBTYPE ))) { +fprintf (stderr,"### %s:%s:EVB Config disabled\n" , + __func__, ed->ifname); +return TLV_OK ; + } + +fprintf (stderr,"%s:type %i, length %i, info " , __func__, tlv->type, tlv->length); + +for (i=0 ; i < tlv->length; i++) { +fprintf (stderr,"%02x " , tlv->info[i]); + } + +printf ("\n" ); + +evb_print_tlvinfo (tie); + +/* change state */ +evb_statemachine (ed, tie); + +/* check which values have been taken over */ +evb_print_tlvinfo (ed->tie); + } + +return TLV_OK ; +} + +void evb_ifdown (char *ifname) +{ +struct evb_data *ed; + +printf ("%s called !\n" , __func__); + + ed =evb_data (ifname); +if (!ed) + goto out_err;
lldp_evb.c line 556
Quoted 10 lines
lldp_evb.c new file +10
-0+ +free (ed->tie); +LIST_REMOVE (ed, entry); +evb_free_tlv (ed); +free (ed); +fprintf (stderr,"### %s:port %s removed\n" , __func__, ifname); +return ; +out_err: +fprintf (stderr,"### %s:port %s adding failed\n" , __func__, ifname); +
This error message is a cut and paste error from ifup? Nothing is being added here suspect "port %s remove failed" would be more accurate.
Quoted 6 lines
lldp_evb.c new file +6
-0+return ; +} + +void evb_ifup (char *ifname) +{ +struct evb_data *ed;
lldp_evb.c line 572
Quoted 10 lines
lldp_evb.c new file +10
-0+struct evb_user_data *ud; + + ed =evb_data (ifname); +if (ed) { +fprintf (stderr,"### %s:%s exists\n" , __func__, ifname); + goto out_err; + } + +/* not found, alloc/init per-port tlv data */ + ed = (struct evb_data *)calloc (1 ,sizeof (struct evb_data ));
Use malloc for calloc of one.
Quoted 22 lines
lldp_evb.c new file +22
-0+if (!ed) { +fprintf (stderr,"### %s:%s malloc %ld failed\n" , + __func__, ifname,sizeof (*ed)); + goto out_err; + } +strncpy (ed->ifname, ifname,IFNAMSIZ ); + +if (!init_cfg ()) { + goto out_err; + } + +if (evb_init_cfg_tlv (ed)) { +fprintf (stderr,"### %s:%s evb_init_cfg_tlv failed\n" , __func__, ifname); +free (ed); + goto out_err; + } + + ed->state =EVB_OFFER_CAPABILITIES ; + +if (evb_bld_tlv (ed)) { +fprintf (stderr,"### %s:%s evb_bld_tlv failed\n" , __func__, ifname); +free (ed);
lldp_evb.c line 604
Quoted 10 lines
lldp_evb.c new file +10
-0+ goto out_err; + } + + ud =find_module_user_data_by_if (ifname, &lldp_head,LLDP_MOD_EVB ); +LIST_INSERT_HEAD (&ud->head, ed, entry); +fprintf (stderr,"### %s:port %s added\n" , __func__, ifname); +return ; + +out_err: +fprintf (stderr,"### %s:port %s adding failed\n" , __func__, ifname);
This error message is a bit misleading if it comes from ed already existing.
Quoted 516 lines
lldp_evb.c new file +54
-0+return ; +} + +static const struct lldp_mod_ops evb_ops = { + .lldp_mod_register = evb_register, + .lldp_mod_unregister = evb_unregister, + .lldp_mod_gettlv = evb_gettlv, + .lldp_mod_rchange = evb_rchange, + .lldp_mod_ifup = evb_ifup, + .lldp_mod_ifdown = evb_ifdown, + .get_arg_handler = evb_get_arg_handlers, +}; + +struct lldp_module *evb_register (void ) +{ +struct lldp_module *mod; +struct evb_user_data *ud; + + mod =malloc (sizeof (*mod)); +if (!mod) { +fprintf (stderr,"failed to malloc module data\n" ); +log_message (MSG_ERR_SERVICE_START_FAILURE , +"%s" ,"failed to malloc module data" ); + goto out_err; + } + ud =malloc (sizeof (struct evb_user_data )); +if (!ud) { +free (mod); +fprintf (stderr,"failed to malloc module user data\n" ); +log_message (MSG_ERR_SERVICE_START_FAILURE , +"%s" ,"failed to malloc module user data" ); + goto out_err; + } +LIST_INIT (&ud->head); + mod->id =LLDP_MOD_EVB ; + mod->ops = &evb_ops; + mod->data = ud; +fprintf (stderr,"### %s:done\n" , __func__); +return mod; + +out_err: +fprintf (stderr,"### %s:failed\n" , __func__); +return NULL ; +} + +void evb_unregister (struct lldp_module *mod) +{ +if (mod->data) { +evb_free_data ((struct evb_user_data *) mod->data); +free (mod->data); + } +free (mod); +fprintf (stderr,"### %s:done\n" , __func__); +}lldp_evb_clif.c new file +226
-0@@ -0,0 +1,226 @@ +/******************************************************************************* + +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". + +*******************************************************************************/ + +#include "includes.h" +#include "common.h" +#include <stdio.h> +#include <syslog.h> +#include <sys/un.h> +#include <sys/stat.h> +#include "lldp_mod.h" +#include "lldptool.h" +#include "lldp.h" +#include "lldp_evb.h" +#include "lldp_evb_clif.h" + +void evb_print_cfg_tlv (u16 ,char *info); +int evb_print_help (); + +u32 evb_lookup_tlv_name (char *tlvid_str); + +static const struct lldp_mod_ops evb_ops_clif = { + .lldp_mod_register = evb_cli_register, + .lldp_mod_unregister = evb_cli_unregister, + .print_tlv = evb_print_tlv, + .lookup_tlv_name = evb_lookup_tlv_name, + .print_help = evb_print_help, +}; + +struct type_name_info evb_tlv_names[] = { + { (LLDP_MOD_EVB <<8 ) |LLDP_EVB_SUBTYPE , +"EVB Configuration TLV" , +"evbCfg" , evb_print_cfg_tlv }, + {INVALID_TLVID ,NULL ,NULL } +}; + +int evb_print_help () +{ +struct type_name_info *tn = &evb_tlv_names[0 ]; + +while (tn->type !=INVALID_TLVID ) { +if (tn->key &&strlen (tn->key) && tn->name) { +printf (" %s" , tn->key); +if (strlen (tn->key)+3 <=8 ) +printf ("\t" ); +printf ("\t: %s\n" , tn->name); + } + tn++; + } + +return 0 ; +} + +struct lldp_module *evb_cli_register (void ) +{ +struct lldp_module *mod; + + mod =malloc (sizeof (*mod)); +if (!mod) { +fprintf (stderr,"failed to malloc module data\n" ); +return NULL ; + } + mod->id =LLDP_MOD_EVB ; + mod->ops = &evb_ops_clif; + +return mod; +} + +void evb_cli_unregister (struct lldp_module *mod) +{ +free (mod); +} + +void evb_print_cfg_tlv (u16 len,char *info) +{ +u8 smode; +u8 scap; +u8 cmode; +u8 ccap; +u16 svsi; +u16 cvsi; +u8 rte; + +if (len !=9 ) { +printf ("Bad Cfg TLV: %s\n" , info); +return ; + } + +if (!hexstr2bin (info, &smode,sizeof (smode))) { +printf ("supported forwarding mode: (0x%02hhx)" , smode); + +if (smode &LLDP_EVB_CAPABILITY_FORWARD_REFLECTIVE_RELAY ) +printf (" reflective relay" ); + +if (smode &LLDP_EVB_CAPABILITY_FORWARD_STANDARD ) +printf (" standard 802.1Q" ); + +printf ("\n" ); + }else { +printf ("Unable to decode smode !\n" ); + } + +if (!hexstr2bin (info+2 , &scap,sizeof (scap))) { +printf ("\tsupported capabilities: (0x%02hhx)" , scap); + +if ( scap &LLDP_EVB_CAPABILITY_PROTOCOL_RTE ) +printf (" RTE" ); + +if ( scap &LLDP_EVB_CAPABILITY_PROTOCOL_ECP ) +printf (" ECP" ); + +if ( scap &LLDP_EVB_CAPABILITY_PROTOCOL_VDP ) +printf (" VDP" ); + +printf ("\n" ); + }else { +printf ("Unable to decode scap !\n" ); + } + +if (!hexstr2bin (info+4 , &cmode,sizeof (cmode))) { +printf ("\tconfigured forwarding mode: (0x%02hhx)" , cmode); + +if (cmode &LLDP_EVB_CAPABILITY_FORWARD_REFLECTIVE_RELAY ) +printf (" reflective relay" ); + +if (cmode &LLDP_EVB_CAPABILITY_FORWARD_STANDARD ) +printf (" standard 802.1Q" ); + +printf ("\n" ); + }else { +printf ("Unable to decode cmode !\n" ); + } + +if (!hexstr2bin (info+6 , &ccap,sizeof (ccap))) { +printf ("\tconfigured capabilities: (0x%02hhx)" , ccap); + +if ( ccap &LLDP_EVB_CAPABILITY_PROTOCOL_RTE ) +printf (" RTE" ); + +if ( ccap &LLDP_EVB_CAPABILITY_PROTOCOL_ECP ) +printf (" ECP" ); + +if ( ccap &LLDP_EVB_CAPABILITY_PROTOCOL_VDP ) +printf (" VDP" ); + +printf ("\n" ); + }else { +printf ("Unable to decode ccap !\n" ); + } + +if (!hexstr2bin (info+8 , (u8 *)&svsi,sizeof (svsi))) { +printf ("\tno. of supported VSIs: %04i\n" ,svsi); + }else { +printf ("Unable to decode svsi !\n" ); + } + +if (!hexstr2bin (info+12 , (u8 *)&cvsi,sizeof (cvsi))) { +printf ("\tno. of configured VSIs: %04i\n" ,cvsi); + }else { +printf ("Unable to decode cvsi !\n" ); + } + +if (!hexstr2bin (info+16 , &rte,sizeof (rte))) { +printf ("\tRTE: %i\n" ,rte); + }else { +printf ("Unable to decode cvsi !\n" ); + } + +printf ("\n" ); +} + +/* return 1: if it printed the TLV +* 0: if it did not +*/ +int evb_print_tlv (u32 tlvid,u16 len,char *info) +{ +struct type_name_info *tn = &evb_tlv_names[0 ]; + +while (tn->type !=INVALID_TLVID ) { +if (tlvid == tn->type) { +printf ("%s\n" , tn->name); +if (tn->print_info) { +printf ("\t" ); + tn->print_info (len-4 , info); + } +return 1 ; + } + tn++; + } + +return 0 ; +} + +u32 evb_lookup_tlv_name (char *tlvid_str) +{ +struct type_name_info *tn = &evb_tlv_names[0 ]; + +while (tn->type !=INVALID_TLVID ) { +if (!strcasecmp (tn->key, tlvid_str)) +return tn->type; + tn++; + } +return INVALID_TLVID ; +} +lldp_evb_cmds.c new file +224
-0@@ -0,0 +1,512 @@ +/******************************************************************************* + +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". + +*******************************************************************************/ + +#include "includes.h" +#include "common.h" +#include <stdio.h> +#include <syslog.h> +#include <sys/un.h> +#include <sys/stat.h> +#include <arpa/inet.h> +#include <string.h> +#include "lldpad.h" +#include "ctrl_iface.h" +#include "lldp.h" +#include "lldp_evb.h" +#include "lldp_mand_clif.h" +#include "lldp_evb_clif.h" +#include "lldp/ports.h" +#include "libconfig.h" +#include "config.h" +#include "clif_msgs.h" +#include "lldp/states.h" + +static int get_arg_tlvtxenable (struct cmd *,char *,char *,char *); +static int set_arg_tlvtxenable (struct cmd *,char *,char *,char *); + +static int get_arg_fmode (struct cmd *,char *,char *,char *); +static int set_arg_fmode (struct cmd *,char *,char *,char *); + +static int get_arg_rte (struct cmd *,char *,char *,char *); +static int set_arg_rte (struct cmd *,char *,char *,char *); + +static int get_arg_vsis (struct cmd *,char *,char *,char *); +static int set_arg_vsis (struct cmd *,char *,char *,char *); + +static int get_arg_capabilities (struct cmd *,char *,char *,char *); +static int set_arg_capabilities (struct cmd *,char *,char *,char *); + +static struct arg_handlers arg_handlers[] = { + {ARG_EVB_FORWARDING_MODE , get_arg_fmode, set_arg_fmode }, + {ARG_EVB_CAPABILITIES , get_arg_capabilities, set_arg_capabilities }, + {ARG_EVB_VSIS , get_arg_vsis, set_arg_vsis }, + {ARG_EVB_RTE , get_arg_rte, set_arg_rte }, + {ARG_TLVTXENABLE , get_arg_tlvtxenable, set_arg_tlvtxenable }, + {NULL } +}; + +static int get_arg_tlvtxenable (struct cmd *cmd,char *arg,char *argvalue, +char *obuf) +{ +int value; +char *s; +char arg_path[EVB_BUF_SIZE ]; + +if (cmd->cmd != cmd_gettlv) +return cmd_invalid; + +switch (cmd->tlvid) { +case (LLDP_MOD_EVB <<8 ) |LLDP_EVB_SUBTYPE : +snprintf (arg_path,sizeof (arg_path),"%s%08x.%s" , +TLVID_PREFIX , cmd->tlvid, arg); + +if (get_cfg (cmd->ifname, arg_path, (void *)&value, +CONFIG_TYPE_BOOL )) + value = false; +break ; +case INVALID_TLVID : +return cmd_invalid; +default : +return cmd_not_applicable; + } + +if (value) + s =VAL_YES ; +else + s =VAL_NO ; + +sprintf (obuf,"%02x%s%04x%s" , (unsigned int )strlen (arg), arg, + (unsigned int )strlen (s), s); + +return cmd_success; +} + +static int set_arg_tlvtxenable (struct cmd *cmd,char *arg,char *argvalue, +char *obuf) +{ +int value; +char arg_path[EVB_BUF_SIZE ]; + +if (cmd->cmd != cmd_settlv) +return cmd_invalid; + +switch (cmd->tlvid) { +case (LLDP_MOD_EVB <<8 ) |LLDP_EVB_SUBTYPE : +break ; +case INVALID_TLVID : +return cmd_invalid; +default : +return cmd_not_applicable; + } + +if (!strcasecmp (argvalue,VAL_YES )) + value =1 ; +else if (!strcasecmp (argvalue,VAL_NO )) + value =0 ; +else +return cmd_invalid; + +snprintf (arg_path,sizeof (arg_path),"%s%08x.%s" , +TLVID_PREFIX , cmd->tlvid, arg); + +if (set_cfg (cmd->ifname, arg_path, (void *)&value,CONFIG_TYPE_BOOL )) +return cmd_failed; + +return cmd_success; +} + +static int get_arg_fmode (struct cmd *cmd,char *arg,char *argvalue, +char *obuf) +{ +char *s; +struct evb_data *ed; + +if (cmd->cmd != cmd_gettlv) +return cmd_invalid; + +switch (cmd->tlvid) { +case (LLDP_MOD_EVB <<8 ) |LLDP_EVB_SUBTYPE : +break ; +case INVALID_TLVID : +return cmd_invalid; +default : +return cmd_not_applicable; + } + + ed =evb_data ((char *) &cmd->ifname); +if (!ed) +return cmd_invalid; +if (ed->policy->smode &LLDP_EVB_CAPABILITY_FORWARD_REFLECTIVE_RELAY ) + s =VAL_EVB_FMODE_BRIDGE ; +else + s =VAL_EVB_FMODE_REFLECTIVE_RELAY ; + +sprintf (obuf,"%02x%s%04x%s" , (unsigned int )strlen (arg), arg, + (unsigned int )strlen (s), s); + +return cmd_success; +} + +static int set_arg_fmode (struct cmd *cmd,char *arg,char *argvalue, +char *obuf) +{ +u8 smode; +char arg_path[EVB_BUF_SIZE ]; +struct evb_data *ed; + +if (cmd->cmd != cmd_settlv) +return cmd_invalid; + +switch (cmd->tlvid) { +case (LLDP_MOD_EVB <<8 ) |LLDP_EVB_SUBTYPE : +break ; +case INVALID_TLVID : +return cmd_invalid; +default : +return cmd_not_applicable; + } + + ed =evb_data ((char *) &cmd->ifname); + +if (!ed) +return cmd_invalid; + + smode =0 ; + +if (!strcasecmp (argvalue,VAL_EVB_FMODE_BRIDGE )) { + smode =LLDP_EVB_CAPABILITY_FORWARD_STANDARD ; + } + +if (!strcasecmp (argvalue,VAL_EVB_FMODE_REFLECTIVE_RELAY )) { + smode =LLDP_EVB_CAPABILITY_FORWARD_REFLECTIVE_RELAY ; + } + +if (smode ==0 ) { +return cmd_invalid; + }else { + ed->policy->smode = smode; + } + +snprintf (arg_path,sizeof (arg_path),"%s%08x.fmode" , +TLVID_PREFIX , cmd->tlvid); + +if (set_cfg (ed->ifname, arg_path, (void *) &argvalue,CONFIG_TYPE_STRING )) { +printf ("%s:%s: saving EVB forwarding mode failed.\n" , + __func__, ed->ifname); +return cmd_invalid; + } + +return cmd_success; +} + +static int get_arg_capabilities(struct cmd *cmd, char *arg, char *argvalue,
lldp_evb_cmds.c line 234
Quoted 10 lines
lldp_evb_cmds.c new file +10
-0+ char *obuf) +{ +int c; +char *s, *t; +struct evb_data *ed; + +printf ("%s(%i): arg %s, argvalue %s !\n" , __func__, __LINE__, arg, argvalue); + + s = t =malloc (EVB_BUF_SIZE ); +
This looks like a memory leak? Where does s or t get free'd.
lldp_evb_cmds.c line 241
Quoted 7 lines
lldp_evb_cmds.c new file +7
-0+if (!s) +return cmd_invalid; + +memset (s,0 ,EVB_BUF_SIZE ); + +if (cmd->cmd != cmd_gettlv) +return cmd_invalid;
certainly a memory leak if 'cmd != cmd_gettlv'.
Quoted 66 lines
lldp_evb_cmds.c new file +66
-0+ +switch (cmd->tlvid) { +case (LLDP_MOD_EVB <<8 ) |LLDP_EVB_SUBTYPE : +break ; +case INVALID_TLVID : +return cmd_invalid; +default : +return cmd_not_applicable; + } + + ed =evb_data ((char *) &cmd->ifname); +if (!ed) +return cmd_invalid; + +if (ed->policy->scap &LLDP_EVB_CAPABILITY_PROTOCOL_RTE ) { + c =sprintf (s,VAL_EVB_CAPA_RTE " " ); +if (c <=0 ) +return cmd_invalid; + s += c; + } + +if (ed->policy->scap &LLDP_EVB_CAPABILITY_PROTOCOL_ECP ) { + c =sprintf (s,VAL_EVB_CAPA_ECP " " ); +if (c <=0 ) +return cmd_invalid; + s += c; + } + +if (ed->policy->scap &LLDP_EVB_CAPABILITY_PROTOCOL_VDP ) { + c =sprintf (s,VAL_EVB_CAPA_VDP " " ); +if (c <=0 ) +return cmd_invalid; + s += c; + } + +sprintf (obuf,"%02x%s%04x%s" , (unsigned int )strlen (arg), arg, + (unsigned int )strlen (t), t); + +return cmd_success; +} + +static int set_arg_capabilities (struct cmd *cmd,char *arg,char *argvalue, +char *obuf) +{ +u8 scap =0 ; +char arg_path[EVB_BUF_SIZE ]; +struct evb_data *ed; + +if (cmd->cmd != cmd_settlv) +return cmd_invalid; + +switch (cmd->tlvid) { +case (LLDP_MOD_EVB <<8 ) |LLDP_EVB_SUBTYPE : +break ; +case INVALID_TLVID : +return cmd_invalid; +default : +return cmd_not_applicable; + } + + ed =evb_data ((char *) &cmd->ifname); + +if (!ed) +return cmd_invalid; + +if (strcasestr (argvalue,VAL_EVB_CAPA_RTE )) {
lldp_evb_cmds.c line 317
Quoted 10 lines
lldp_evb_cmds.c new file +10
-0+ scap |=LLDP_EVB_CAPABILITY_PROTOCOL_RTE ; + } + +if (strcasestr (argvalue,VAL_EVB_CAPA_ECP )) { + scap |=LLDP_EVB_CAPABILITY_PROTOCOL_ECP ; + } + +if (strcasestr (argvalue,VAL_EVB_CAPA_VDP )) { + scap |=LLDP_EVB_CAPABILITY_PROTOCOL_VDP ; + }
Fix the above indentation scap has one too many tabs. Remove the extra braces as well.
Quoted 61 lines
lldp_evb_cmds.c new file +61
-0+ + ed->policy->scap = scap; + +snprintf (arg_path,sizeof (arg_path),"%s%08x.capabilities" , +TLVID_PREFIX , cmd->tlvid); + +if (set_cfg (ed->ifname, arg_path, (void *) &argvalue,CONFIG_TYPE_STRING )) { +printf ("%s:%s: saving EVB capabilities failed.\n" , + __func__, ed->ifname); +return cmd_invalid; + } + +return cmd_success; +} + +static int get_arg_rte (struct cmd *cmd,char *arg,char *argvalue, +char *obuf) +{ +char s[EVB_BUF_SIZE ]; +struct evb_data *ed; + +if (cmd->cmd != cmd_gettlv) +return cmd_invalid; + +switch (cmd->tlvid) { +case (LLDP_MOD_EVB <<8 ) |LLDP_EVB_SUBTYPE : +break ; +case INVALID_TLVID : +return cmd_invalid; +default : +return cmd_not_applicable; + } + + ed =evb_data ((char *) &cmd->ifname); +if (!ed) +return cmd_invalid; + +if (sprintf (s,"%i" , ed->policy->rte) <=0 ) +return cmd_invalid; + +sprintf (obuf,"%02x%s%04x%s" , (unsigned int )strlen (arg), arg, + (unsigned int )strlen (s), s); + +return cmd_success; +} + +static int set_arg_rte (struct cmd *cmd,char *arg,char *argvalue, +char *obuf) +{ +int value, err; +char arg_path[EVB_BUF_SIZE ]; +char svalue[10 ]; +char *sv; +struct evb_data *ed =NULL ; + +if (cmd->cmd != cmd_settlv) + goto out_err; + +switch (cmd->tlvid) { +case (LLDP_MOD_EVB <<8 ) |LLDP_EVB_SUBTYPE : +break ;
lldp_evb_cmds.c line 388
Quoted 10 lines
lldp_evb_cmds.c new file +10
-0+case INVALID_TLVID : + goto out_err; +default : +return cmd_not_applicable; + } + + ed =evb_data ((char *) &cmd->ifname); + +if (!ed) + goto out_err;
'goto out_err' will cause a null pointer dereference on ed->ifname below.
Quoted 14 lines
lldp_evb_cmds.c new file +14
-0+ + value =atoi (argvalue); + +if ((value <0 )) + goto out_err; + + ed->policy->rte = value; + + err =snprintf (arg_path,sizeof (arg_path),"%s%08x.rte" , +TLVID_PREFIX , cmd->tlvid); + +if (err <0 ) + goto out_err; +
lldp_evb_cmds.c line 412
Quoted 10 lines
lldp_evb_cmds.c new file +10
-0+ err =snprintf (svalue,sizeof (svalue),"%i" , value); + +if (err <0 ) + goto out_err; + + sv = &svalue[0 ]; + +if (set_cfg (ed->ifname, arg_path, (void *) &sv,CONFIG_TYPE_STRING )) { + goto out_err; + }
Is this correct '&sv' why not just use svalue.
Quoted 83 lines
lldp_evb_cmds.c new file +83
-0+ +return cmd_success; + +out_err: +printf ("%s:%s: saving EVB rte failed.\n" , __func__, ed->ifname); +return cmd_invalid; +} + +static int get_arg_vsis (struct cmd *cmd,char *arg,char *argvalue, +char *obuf) +{ +char s[EVB_BUF_SIZE ]; +struct evb_data *ed; + +if (cmd->cmd != cmd_gettlv) +return cmd_invalid; + +switch (cmd->tlvid) { +case (LLDP_MOD_EVB <<8 ) |LLDP_EVB_SUBTYPE : +break ; +case INVALID_TLVID : +return cmd_invalid; +default : +return cmd_not_applicable; + } + + ed =evb_data ((char *) &cmd->ifname); +if (!ed) +return cmd_invalid; + +if (sprintf (s,"%04i" , ed->policy->svsi) <=0 ) +return cmd_invalid; + +sprintf (obuf,"%02x%s%04x%s" , (unsigned int )strlen (arg), arg, + (unsigned int )strlen (s), s); + +return cmd_success; +} + +static int set_arg_vsis (struct cmd *cmd,char *arg,char *argvalue, +char *obuf) +{ +int value, err; +char arg_path[EVB_BUF_SIZE ]; +char svalue[10 ]; +char *sv; +struct evb_data *ed =NULL ; + +if (cmd->cmd != cmd_settlv) + goto out_err; + +switch (cmd->tlvid) { +case (LLDP_MOD_EVB <<8 ) |LLDP_EVB_SUBTYPE : +break ; +case INVALID_TLVID : + goto out_err; +default : +return cmd_not_applicable; + } + + ed =evb_data ((char *) &cmd->ifname); + +if (!ed) + goto out_err; + + value =atoi (argvalue); + +if ((value <0 ) || (value >LLDP_EVB_DEFAULT_MAX_VSI )) + goto out_err; + + ed->policy->svsi = value; + + err =snprintf (arg_path,sizeof (arg_path),"%s%08x.vsis" , +TLVID_PREFIX , cmd->tlvid); + +if (err <0 ) + goto out_err; + + err =snprintf (svalue,sizeof (svalue),"%i" , value); + +if (err <0 ) + goto out_err; +
lldp_evb_cmds.c line 505
Quoted 10 lines
lldp_evb_cmds.c new file +10
-0+ sv = &svalue[0 ]; + +if (set_cfg (ed->ifname, arg_path, (void *) &sv,CONFIG_TYPE_STRING )) { + goto out_err; + } + +return cmd_success; + +out_err: +printf ("%s:%s: saving EVB vsis failed.\n" , __func__, ed->ifname);
'goto out_err' is used above twice before ed has been initialized.
Quoted 40 lines
lldp_evb_cmds.c new file +7
-0+return cmd_invalid; +} + +struct arg_handlers *evb_get_arg_handlers () +{ +return &arg_handlers[0 ]; +}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 +1
-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"
lldptool.c struct lldp_module *(*register_tlv_table[])(void) = { · line 163
Quoted 7 lines
lldptool.c +1
-0@@ -156,6 +157,7 @@ struct lldp_module *(*register_tlv_table[])(void) = { ieee8023_cli_register, med_cli_register, dcbx_cli_register, + evb_cli_register, NULL, };
Jens, in general this looks OK. Can you fix the coding style throughout I prefer for single line if statements,
if (x)
a_line; else (y) b_line;
The intent here is to use the same coding style as linux kernel where it is reasonable to do so. Like I said before I know lldpad is not at all consistent in this regard, but I want to get the rest of the code in order and certainly have new code be consistent.
Thanks!
John
Re: [E1000-eedc] [PATCH 02/10] implementation of IEEE 802.1Qbg in lldpad, part 1
Quoted 460 lines · John Fastabend
Quoted 428 lines · Jens Osterkamp
This 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.
Signed-off-by Jens Osterkamp <[email protected]>--- 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 | 658 +++++++++++++++++++++++++++++++++++++++++++++++ lldp_evb_clif.c | 226 ++++++++++++++++ lldp_evb_cmds.c | 512 ++++++++++++++++++++++++++++++++++++ lldpad.c | 2 + lldptool.c | 2 + 11 files changed, 1588 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.cMakefile.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.hinclude/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 4096 +#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@@ -0,0 +1,80 @@ +/******************************************************************************* + +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_H +#define _LLDP_EVB_H + +#include "lldp_mod.h" + +#define LLDP_MOD_EVB OUI_IEEE_8021Qbg +#define LLDP_OUI_SUBTYPE { 0x00, 0x1b, 0x3f, 0x00 } + +typedef enum { +EVB_OFFER_CAPABILITIES =0 , +EVB_CONFIGURE , +EVB_CONFIRMATION +}evb_state ; + +struct tlv_info_evb { +u8 oui[3 ]; +u8 sub; +/* supported forwarding mode */ +u8 smode; +/* supported capabilities */ +u8 scap; +/* currently configured forwarding mode */ +u8 cmode; +/* currently configured capabilities */ +u8 ccap; +/* supported no. of vsi */ +u16 svsi; +/* currently configured no. of vsi */ +u16 cvsi; +/* retransmission exponent */ +u8 rte; +} __attribute__ ((__packed__ )); + +struct evb_data { +char ifname[IFNAMSIZ ]; +struct unpacked_tlv *evb; +struct tlv_info_evb *tie; +/* local policy */ +struct tlv_info_evb *policy; +int state; +LIST_ENTRY (evb_data) entry; +}; + +struct evb_user_data { + LIST_HEAD(evb_head, evb_data) head; +}; + +struct lldp_module *evb_register (void ); +void evb_unregister (struct lldp_module *mod); +struct packed_tlv *evb_gettlv (struct port *port); +void evb_ifdown (char *); +void evb_ifup (char *); +struct evb_data *evb_data (char *ifname); + +#endif /* _LLDP_EVB_H */ include/lldp_evb_clif.h new file +51
-0@@ -0,0 +1,51 @@ +/******************************************************************************* + +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_CLIF_H +#define _LLDP_EVB_CLIF_H + +struct lldp_module *evb_cli_register (void ); +void evb_cli_unregister (struct lldp_module *); +int evb_print_tlv (u32 ,u16 ,char *); + +#define EVB_BUF_SIZE 256 + +#define ARG_EVB_FORWARDING_MODE "fmode" + +#define VAL_EVB_FMODE_BRIDGE "bridge" +#define VAL_EVB_FMODE_REFLECTIVE_RELAY "reflectiverelay" + +#define ARG_EVB_CAPABILITIES "capabilities" + +#define VAL_EVB_CAPA_RTE "rte" +#define VAL_EVB_CAPA_ECP "ecp" +#define VAL_EVB_CAPA_VDP "vdp" +#define VAL_EVB_CAPA_NONE "none" + +#define ARG_EVB_VSIS "vsis" + +#define ARG_EVB_RTE "rte" + +#endif 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 +102
-0@@ -0,0 +1,658 @@ +/******************************************************************************* + +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". + +*******************************************************************************/ + +#include <net/if.h> +#include <sys/queue.h> +#include <sys/socket.h> +#include <sys/ioctl.h> +#include <sys/utsname.h> +#include <linux/if_bridge.h> +#include <string.h> +#include "lldp.h" +#include "lldp_evb.h" +#include "messages.h" +#include "config.h" +#include "common.h" +#include "lldp_mand_clif.h" +#include "lldp_evb_clif.h" +#include "lldp_evb_cmds.h" + +extern struct lldp_head lldp_head; + +struct evb_data *evb_data (char *ifname) +{ +struct evb_user_data *ud; +struct evb_data *ed =NULL ; + + ud =find_module_user_data_by_if (ifname, &lldp_head,LLDP_MOD_EVB ); +if (ud) { + LIST_FOREACH(ed, &ud->head, entry) { +if (!strncmp (ifname, ed->ifname,IFNAMSIZ )) +return ed; + } + } +return NULL ; +} + +static void evb_print_tlvinfo (struct tlv_info_evb *tie) +{ +printf ("%s(%i): supported forwarding mode: %02x\n" , __FILE__, __LINE__, tie->smode); +printf ("%s(%i): configured forwarding mode: %02x\n" , __FILE__, __LINE__, tie->cmode); +printf ("%s(%i): supported capabilities: %02x\n" , __FILE__, __LINE__, tie->scap); +printf ("%s(%i): configured capabilities: %02x\n" , __FILE__, __LINE__, tie->ccap); +printf ("%s(%i): supported no. of vsis: %04i\n" , __FILE__, __LINE__, tie->svsi); +printf ("%s(%i): configured no. of vsis: %04i\n" , __FILE__, __LINE__, tie->cvsi); +printf ("%s(%i): rte: %02i\n\n" , __FILE__, __LINE__, tie->rte); +} + +/* +* evb_bld_cfg_tlv - build the EVB TLV +* @ed: the evb data struct +* +* Returns 0 on success +*/ +static int evb_bld_cfg_tlv (struct evb_data *ed) +{ +int rc =0 ; +int i; +struct unpacked_tlv *tlv =NULL ; + +/* free ed->evb if it exists */ +FREE_UNPKD_TLV (ed, evb); + +if (!is_tlv_txenabled (ed->ifname,TLVID_8021Qbg (LLDP_EVB_SUBTYPE ))) { +fprintf (stderr,"%s:%s:EVB tx is currently disabled !\n" , + __func__, ed->ifname); + rc =EINVAL ; + goto out_err; + } + + tlv =create_tlv (); +if (!tlv) + goto out_err; + + tlv->type =ORG_SPECIFIC_TLV ; + tlv->length =sizeof (struct tlv_info_evb ); + tlv->info = (u8 *)malloc (tlv->length); +if (!tlv->info) { +free (tlv); + tlv =NULL ; + rc =ENOMEM ;lldp_evb.c line 112
Quoted 10 lines
lldp_evb.c new file +10
-0+ goto out_err; + } +memcpy (tlv->info, ed->tie, tlv->length); + +printf ("### %s:type %i, length %i, info " , __func__, tlv->type, tlv->length); + +for (i=0 ; i < tlv->length; i++) { +printf ("%02x " , tlv->info[i]); + } +Remove the extra braces around the for statement. Granted the rest of lldpad may not follow a consistent coding style but lets try going forward and hopefully I get around to lldpad soon.
lldp_evb.c line 124
Quoted 12 lines
lldp_evb.c new file +12
-0+printf ("\n" ); + + ed->evb = tlv; +out_err: +return rc; +} + +static void evb_free_tlv (struct evb_data *ed) +{ +if (ed) { +FREE_UNPKD_TLV (ed, evb); + }Same here extra braces.
Quoted 16 lines
lldp_evb.c line 137
Quoted 13 lines
lldp_evb.c new file +13
-0+} + +/* evb_init_cfg_tlv: +* +* fill up tlv_info_evb structure with reasonable info +*/ +static int evb_init_cfg_tlv (struct evb_data *ed) +{ +char arg_path[EVB_BUF_SIZE ]; +char *param; + +/* load policy from config */ + ed->policy = (struct tlv_info_evb *)calloc (1 ,sizeof (struct tlv_info_evb ));Use malloc instead of
callod()of one.
On second thought disregard this nit. Keep the calloc() calls if you want and ignore the comment. I guess you save a memset() this way...
Thanks,
John
Re: [E1000-eedc] [PATCH 02/10] implementation of IEEE 802.1Qbg in lldpad, part 1
In reply to John FastabendQuoted 28 lines · John Fastabend
Quoted 27 lines · Jens Osterkamp
This 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.
Signed-off-by Jens Osterkamp <[email protected]>
snip
Quoted 12 lines
remove the unneeded braces in the if statements above.
lldp_evb.c line 403
Quoted 9 lines
lldp_evb.c new file +9
-0+/* only look at the mode for now +if (tie->ccap == ed->tie->ccap) { +ed->tie->ccap = tie->ccap; +} + +if (tie->cvsi == ed->tie->cvsi) { +ed->tie->cvsi = tie->cvsi; +} +*/
Quoted 3 lines
Why is this commented out? I will review the spec shortly, but please remind me. If its not needed remove it and add it later in a clean patch
Its not used right now, so its commented out. I removed it for now.
Quoted 10 lines
Quoted 10 lines
lldp_evb.c new file +9
-0+ +return TLV_OK ; +} + +/* evb_compare +* +* compare our own and received tlv_info_evb +*/ +static int evb_compare (struct evb_data *ed,struct tlv_info_evb *tie)
Quoted 8 lines
lldp_evb.c line 418
Quoted 6 lines
lldp_evb.c new file +6
-0+{ +printf ("%s(%i): \n" , __func__, __LINE__); + +if ((ed->tie->cmode == tie->cmode)/* && +(ed->tie->ccap == tie->ccap) && +(ed->tie->cvsi == tie->cvsi)*/ )Same here if its going to be commented out lets remove it for now.
Removed it.
Quoted 15 lines
Quoted 15 lines
lldp_evb.c new file +14
-0+return 0 ; + else + return 1; +} + +/* evb_statemachine: +* +* handle possible states during EVB capabilities exchange +* +* possible states: EVB_OFFER_CAPABILITIES +* EVB_CONFIGURE +* EVB_CONFIRMATION +*/ +static void evb_statemachine (struct evb_data *ed,struct tlv_info_evb *tie)
snip
Quoted 25 lines
Quoted 13 lines
lldptool.c +1
-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" lldptool.c struct lldp_module *(*register_tlv_table[])(void) = { · line 163
Quoted 7 lines
lldptool.c +1
-0@@ -156,6 +157,7 @@ struct lldp_module *(*register_tlv_table[])(void) = { ieee8023_cli_register, med_cli_register, dcbx_cli_register, + evb_cli_register, NULL, };Jens, in general this looks OK. Can you fix the coding style throughout I prefer for single line if statements,
if (x)
Quoted 8 lines
a_line; else (y) b_line;The intent here is to use the same coding style as linux kernel where it is reasonable to do so. Like I said before I know lldpad is not at all consistent in this regard, but I want to get the rest of the code in order and certainly have new code be consistent.
fixed this in all the places I could find.
I will address the rest your comments in my next posting of the series.
Thanks !
Jens
Signature · 5 lines
IBM Deutschland Research & Development GmbH Vorsitzender des Aufsichtsrats: Martin Jetter Geschäftsführung: Dirk Wittkopp Sitz der Gesellschaft: Böblingen Registergericht: Amtsgericht Stuttgart, HRB 243294
PATCH 3/10 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/10 ECP implementation
In reply to Jens OsterkampThis is the implementation of the edge control protocol (ECP) as specified in IEEE 802.1Qbg.
For this it 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.
--- Makefile.am | 2 + ecp/ecp.c | 77 +++++++ ecp/ecp.h | 92 ++++++++ ecp/ecp_rx.c | 597 ++++++++++++++++++++++++++++++++++++++++++++++++++++ ecp/ecp_tx.c | 467 ++++++++++++++++++++++++++++++++++++++++ include/lldp_evb.h | 6 + include/lldp_vdp.h | 157 ++++++++++++++ lldp/l2_packet.h | 2 + lldp/ports.h | 25 ++- 9 files changed, 1422 insertions(+), 3 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
Makefile.am +2 -0
@@ -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 \
ecp/ecp.c new file +77 -0
77 lines not on this page · raw message
ecp/ecp.h new file +92 -0
92 lines not on this page · raw message
ecp/ecp_rx.c new file +597 -0
597 lines not on this page · raw message
ecp/ecp_tx.c new file +467 -0
467 lines not on this page · raw message
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 +157 -0
157 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 +22 -3
@@ -136,21 +136,40 @@ struct porttlvs{struct unpacked_tlv *last_peer; }; +struct ecp { +struct l2_packet_data *l2; +int sequence; +int retries; +int ackReceived; +int ackTimerExpired; +u16 lastSequence; +u16 seqECPDU; +struct portrx rx; +struct porttx tx; +struct portstats stats; +}; +struct port {char *ifname;u8 hw_resetting;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 ecp ecp;struct port *next; };
Signature · 1 line
1.7.1
Re: [E1000-eedc] [PATCH 04/10] ECP implementation
Quoted 14 lines · Jens Osterkamp
This is the implementation of the edge control protocol (ECP) as specified in IEEE 802.1Qbg.
For this it 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.
Quoted 1 line
Signed-off-by Jens Osterkamp <[email protected]>
I am hesitant to apply these without a defined ethertype. Presumably this will come out of the IEEE DCB task group.
ecp/ecp.c
Quoted 36 lines
--- Makefile.am | 2 + ecp/ecp.c | 77 +++++++ ecp/ecp.h | 92 ++++++++ ecp/ecp_rx.c | 597 ++++++++++++++++++++++++++++++++++++++++++++++++++++ ecp/ecp_tx.c | 467 ++++++++++++++++++++++++++++++++++++++++ include/lldp_evb.h | 6 + include/lldp_vdp.h | 157 ++++++++++++++ lldp/l2_packet.h | 2 + lldp/ports.h | 25 ++- 9 files changed, 1422 insertions(+), 3 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.hMakefile.am +2
-0@@ -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 \ecp/ecp.c new file +0
-0@@ -0,0 +1,77 @@
snip snip
Quoted 47 lines
ecp/ecp.c new file +47
-0+} + +/* ecp_rx_validate_frame - wrapper around ecp_rx_validateFrame +* @port: currently used port +* +* no return value +* +* sets rcvFrame to false and validates frame. used in ECP_RX_RECEIVE_ECPDU +* state of ecp_rx_run_sm +*/ +void ecp_rx_validate_frame (struct port *port) +{ + port->ecp.rx.rcvFrame = false; +ecp_rx_validateFrame (port); +return ; +} + +/* ecp_rx_ProcessFrame - process received ecp frames +* @port: currently used port +* +* no return value +* +* walks through the packed vsi tlvs in an ecp frame, extracts them +* and passes them to the VDP ULP with vdp_indicate. +*/ +void ecp_rx_ProcessFrame (struct port * port) +{ +u16 tlv_cnt =0 ; +u8 tlv_type =0 ; +u16 tlv_length =0 ; +u16 tlv_offset =0 ; +u16 *tlv_head_ptr =NULL ; +u8 frame_error =0 ; +bool tlv_stored = false; +int err; +struct lldp_module *np; +struct ecp_hdr *ecp_hdr; + +printf ("%s(%i)-%s: processing frame \n" , __func__, __LINE__, port->ifname); + +assert (port->ecp.rx.framein && port->ecp.rx.sizein); + + tlv_offset =sizeof (struct l2_ethhdr ); + +ecp_print_framein (port); + + ecp_hdr = (struct ecp_hdr *)&port->ecp.rx.framein[tlv_offset];
ecp/ecp.c line 57
Quoted 10 lines
ecp/ecp.c new file +10
-0+ +printf ("%s(%i)-%s: ecp packet with subtype %04x, mode %02x, sequence nr %04x\n" , + __func__, __LINE__, port->ifname, ecp_hdr->subtype, ecp_hdr->mode, ecp_hdr->seqnr); + +/* FIXME: already done in ecp_rx_validateFrame ? */ +if (ecp_hdr->subtype !=ECP_SUBTYPE ) { +printf ("ERROR: unknown subtype !\n" ); + frame_error++; + goto out; + }
Agreed looks like above can be removed.
Quoted 85 lines
ecp/ecp.c new file +85
-0+ +/* processing of VSI_TLVs starts here */ + + tlv_offset +=sizeof (struct ecp_hdr ); + +do { + tlv_cnt++; +if (tlv_offset > port->ecp.rx.sizein) { +printf ("%s(%i)-%s: ERROR: Frame overrun! tlv_offset %i, sizein %i cnt %i\n" , + __func__, __LINE__, port->ifname, tlv_offset, port->ecp.rx.sizein, tlv_cnt); + frame_error++; + goto out; + } + + tlv_head_ptr = (u16 *)&port->ecp.rx.framein[tlv_offset]; + tlv_length =htons (*tlv_head_ptr) &0x01FF ; + tlv_type = (u8)(htons (*tlv_head_ptr) >>9 ); + +u16 tmp_offset = tlv_offset + tlv_length; +if (tmp_offset > port->ecp.rx.sizein) { +printf ("ERROR: Frame overflow error: offset=%d, " +"rx.size=%d \n" , tmp_offset, port->ecp.rx.sizein); + frame_error++; + goto out; + } + +u8 *info = (u8 *)&port->ecp.rx.framein[tlv_offset + +sizeof (*tlv_head_ptr)]; + +struct unpacked_tlv *tlv =create_tlv (); + +if (!tlv) { +printf ("ERROR: Failed to malloc space for " +"incoming TLV. \n" ); + goto out; + } + +if ((tlv_length ==0 ) && (tlv->type !=TYPE_0 )) { +printf ("ERROR: tlv_length == 0\n" ); +free_unpkd_tlv (tlv); + goto out; + } + + tlv->type = tlv_type; + tlv->length = tlv_length; + tlv->info = (u8 *)malloc (tlv_length); +if (tlv->info) { +memset (tlv->info,0 , tlv_length); +memcpy (tlv->info, info, tlv_length); + }else { +printf ("ERROR: Failed to malloc space for incoming " +"TLV info \n" ); +free_unpkd_tlv (tlv); + goto out; + } + +/* Validate the TLV */ + tlv_offset +=sizeof (*tlv_head_ptr) + tlv_length; + +if (tlv->type ==TYPE_127 ) {/* private TLV */ +/* TODO: give VSI TLV to VDP */ + } + +if ((tlv->type !=TYPE_0 ) && !tlv_stored) { +printf ("\n%s: allocated TLV (%lu) " +" was not stored! (%p)\n" , __func__, tlv->type, + tlv); + tlv =free_unpkd_tlv (tlv); + port->ecp.stats.statsTLVsUnrecognizedTotal++; + } + + tlv =NULL ; + tlv_stored = false; + }while (tlv_type !=0 ); + +out: +if (frame_error) { + port->ecp.stats.statsFramesDiscardedTotal++; + port->ecp.stats.statsFramesInErrorsTotal++; + port->ecp.rx.badFrame = true; + } + +return ; +} +
snip
Quoted 73 lines
ecp/ecp.c new file +73
-0+ +/* ecp_build_ECPDU - create an ecp protocol data unit +* @port: currently used port +* @mode: mode to create pdu with (REQ or ACK) +* +* returns true on success, false on failure +* +* creates the frame header with the ports mac address, the ecp header with REQ +* or ACK mode, plus a list of packed TLVs created from the profiles on this +* port. +*/ +bool ecp_build_ECPDU (struct port *port,int mode) +{ +struct l2_ethhdr eth; +struct ecp_hdr ecp_hdr; +u8 own_addr[ETH_ALEN ]; +u32 fb_offset =0 ; +u32 datasize =0 ; +struct packed_tlv *ptlv =NULL ; +struct lldp_module *np; +struct vdp_data *vd; +struct vsi_profile *p; + +if (port->ecp.tx.frameout) { +free (port->ecp.tx.frameout); + port->ecp.tx.frameout =NULL ; + } + +/* TODO: different multicast address for sending ECP over S-channel (multi_cast_source_s) +* S-channels to implement later */ +memcpy (eth.h_dest, multi_cast_source,ETH_ALEN ); +l2_packet_get_own_src_addr (port->ecp.l2,(u8 *)&own_addr); +memcpy (eth.h_source, &own_addr,ETH_ALEN ); + eth.h_proto =htons (ETH_P_ECP ); + port->ecp.tx.frameout = (u8 *)malloc (ETH_FRAME_LEN ); +if (port->ecp.tx.frameout ==NULL ) { +printf ("InfoECPDU: Failed to malloc frame buffer \n" ); +return false; + } +memset (port->ecp.tx.frameout,0 ,ETH_FRAME_LEN ); +memcpy (port->ecp.tx.frameout, (void *)ð,sizeof (struct l2_ethhdr )); + fb_offset +=sizeof (struct l2_ethhdr ); + + ecp_hdr.oui[0 ] =0x0 ; + ecp_hdr.oui[1 ] =0x1b ; + ecp_hdr.oui[2 ] =0x3f ; + + ecp_hdr.pad1 =0x0 ; + + ecp_hdr.subtype =ECP_SUBTYPE ; +switch (mode) { +case VDP_PROFILE_REQ : + ecp_hdr.mode =ECP_REQUEST ; +break ; +case VDP_PROFILE_ACK : + ecp_hdr.mode =ECP_ACK ; +break ; +default : +printf ("%s(%i): unknown mode for %s !\n" , __func__, __LINE__, + port->ifname); + } + + ecp_hdr.seqnr = port->ecp.lastSequence; + +if ((sizeof (struct ecp_hdr )+fb_offset) >ETH_MAX_DATA_LEN ) + goto error; +memcpy (port->ecp.tx.frameout+fb_offset, (void *)&ecp_hdr,sizeof (struct ecp_hdr )); + datasize +=sizeof (struct ecp_hdr ); + fb_offset +=sizeof (struct ecp_hdr ); + +/* TODO: create tlvs from profiles here */ + +/* The End TLV marks the end of the LLDP PDU */
ecp/ecp.c
Quoted 10 lines
ecp/ecp.c new file +10
-0+ ptlv =pack_end_tlv (); +if (!ptlv || ((ptlv->size + fb_offset) >ETH_MAX_DATA_LEN )) + goto error; +memcpy (port->ecp.tx.frameout + fb_offset, ptlv->tlv, ptlv->size); + datasize += ptlv->size; + fb_offset += ptlv->size; + ptlv =free_pkd_tlv (ptlv); + +if (datasize <ETH_MIN_DATA_LEN ) + port->ecp.tx.sizeout =ETH_MIN_PKT_LEN ;
Might also be worth checking ETH_MAX_DATA_LEN after the above TODO adding profiles is done.
Quoted 4 lines
ecp/ecp.c new file +4
-0+else + port->ecp.tx.sizeout = fb_offset; + +return true;
ecp/ecp.c
Quoted 10 lines
ecp/ecp.c new file +10
-0+ +error: + ptlv =free_pkd_tlv (ptlv); +if (port->ecp.tx.frameout) +free (port->ecp.tx.frameout); + port->ecp.tx.frameout =NULL ; +printf ("InfoECPDU: packed TLV too large for tx frame\n" ); +return false; +} +
Please merge the relevant pieces of this patch with the following patch so it does not add 'struct ecp' to the port structure then immediately move it to vdp_data in the following patch.
Thanks,
John.
Re: [E1000-eedc] [PATCH 04/10] ECP implementation
Quoted 15 lines · John Fastabend
Quoted 14 lines · Jens Osterkamp
This is the implementation of the edge control protocol (ECP) as specified in IEEE 802.1Qbg.
For this it 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.
Quoted 3 lines
Quoted 1 line
Signed-off-by Jens Osterkamp <[email protected]>I am hesitant to apply these without a defined ethertype. Presumably this will come out of the IEEE DCB task group.
I am not familiar with the IEEE process, but my current understanding is that the ethertype is defined towards the end of the standardization process, and the extended ethertype together with the OUI has to be used until then.
Quoted 40 lines
ecp/ecp.c
Quoted 37 lines
--- Makefile.am | 2 + ecp/ecp.c | 77 +++++++ ecp/ecp.h | 92 ++++++++ ecp/ecp_rx.c | 597 ++++++++++++++++++++++++++++++++++++++++++++++++++++ ecp/ecp_tx.c | 467 ++++++++++++++++++++++++++++++++++++++++ include/lldp_evb.h | 6 + include/lldp_vdp.h | 157 ++++++++++++++ lldp/l2_packet.h | 2 + lldp/ports.h | 25 ++- 9 files changed, 1422 insertions(+), 3 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.hMakefile.am +2
-0@@ -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 \ecp/ecp.c new file +0
-0@@ -0,0 +1,77 @@snip snip
snip
Quoted 1 line
Please merge the relevant pieces of this patch with the following patch so it does not add 'struct ecp' to the port structure then immediately move it to
vdp_datain the following patch.
I will address your comments in my next posting of the series and merge the relevant pieces to the previous patch.
Thanks !
Jens
Signature · 5 lines
IBM Deutschland Research & Development GmbH Vorsitzender des Aufsichtsrats: Martin Jetter Geschäftsführung: Dirk Wittkopp Sitz der Gesellschaft: Böblingen Registergericht: Amtsgericht Stuttgart, HRB 243294
PATCH 5/10 implementation of VDP
In reply to Jens OsterkampThis patch contains an initial implemention of VDP as specified in IEEE 802.1Qbg.
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 | 8 +- ecp/ecp.c | 22 +- ecp/ecp.h | 19 +- ecp/ecp_rx.c | 350 ++++++++-------- ecp/ecp_tx.c | 292 ++++++++------ include/lldp.h | 1 + include/lldp_vdp.h | 10 +- lldp/ports.h | 14 - lldp_vdp.c | 1140 ++++++++++++++++++++++++++++++++++++++++++++++++++++ lldpad.c | 2 + 10 files changed, 1517 insertions(+), 341 deletions(-) create mode 100644 lldp_vdp.c
Makefile.am +4 -4
@@ -69,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 +12 -10
@@ -31,11 +31,11 @@#include <linux/if_bridge.h> #include "lldp.h" #include "lldp_evb.h" +#include "lldp_vdp.h" #include "messages.h" #include "config.h" #include "common.h" #include "lldp/l2_packet.h" -#include "lldp/ports.h" #include "ecp/ecp.h" /* ecp_init - initialize ecp module
@@ -50,25 +50,27 @@*/ int ecp_init (char *ifname) { -struct port *port; +struct vdp_data *vd; - port =port_find_by_name (ifname); +printf ("%s(%i): starting ECP for if %s !\n" , __func__, __LINE__, ifname); -if (!port) { -printf ("%s(%i): unable to find port %s ! \n" , __func__, __LINE__, ifname); + vd =vdp_data (ifname); + +if (!vd) { +printf ("%s(%i): unable to find vd %s ! \n" , __func__, __LINE__, ifname); goto fail; } - port->ecp.l2 =l2_packet_init (port->ifname,NULL ,ETH_P_ECP , - ecp_rx_ReceiveFrame, port,1 ); -if (!port->ecp.l2) { + vd->ecp.l2 =l2_packet_init (vd->ifname,NULL ,ETH_P_ECP , + ecp_rx_ReceiveFrame, vd,1 ); +if (!vd->ecp.l2) {printf ("ERROR: Failed to open register layer 2 access to " "ETH_P_ECP\n" ); goto fail; } -ecp_tx_run_sm (port); -ecp_rx_run_sm (port); +ecp_tx_run_sm (vd); +ecp_rx_run_sm (vd);return 0 ;
ecp/ecp.h +14 -5
@@ -26,8 +26,8 @@#ifndef _ECP_H#define _ECP_H -#include "lldp/ports.h" #include "lldp_mod.h" +#include "include/lldp_vdp.h" #define ECP_SUBTYPE 0x0
@@ -42,6 +42,19 @@ typedef enum {ECP_ACK } ecp_mode; +struct ecp { +struct l2_packet_data *l2; +int sequence; +int retries; +int ackReceived; +int ackTimerExpired; +u16 lastSequence; +u16 seqECPDU; +struct portrx rx; +struct porttx tx; +struct portstats stats; +}; +struct ecp_hdr {u8 oui[3 ];u8 pad1;
@@ -51,7 +64,6 @@ struct ecp_hdr { } __attribute__ ((__packed__));enum { -ECP_TX_IDLE ,ECP_TX_INIT_TRANSMIT ,ECP_TX_TRANSMIT_ECPDU ,ECP_TX_WAIT_FOR_ACK ,
@@ -66,8 +78,6 @@ static const char *ecp_tx_states[] = {"ECP_TX_REQUEST_PDU" }; -void ecp_tx_run_sm (struct port *); -enum {ECP_RX_IDLE ,ECP_RX_INIT_RECEIVE ,
@@ -87,6 +97,5 @@ static const char *ecp_rx_states[] = { };void ecp_rx_ReceiveFrame (void *,unsigned int ,const u8 *,size_t ); -void ecp_rx_run_sm (struct port *);#endif /* _ECP_H */
ecp/ecp_rx.c +179 -171
680 lines not on this page · raw message
ecp/ecp_tx.c +159 -133
568 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_vdp.h +6 -4
@@ -27,6 +27,7 @@#define _LLDP_VDP_H#include "lldp_mod.h" +#include "ecp/ecp.h" #define LLDP_MOD_VDP OUI_IEEE_8021Qbg+1
@@ -101,7 +102,7 @@ struct vsi_profile {int mode;int response;u8 mgrid; -u8 id[3 ]; +int id;u8 version;u8 instance[16 ];u8 mac[6 ];/* TODO: currently only one MAC/VLAN pair supported, more later */
@@ -116,6 +117,7 @@ struct vsi_profile {struct vdp_data {char ifname[IFNAMSIZ ]; +struct ecp ecp;struct unpacked_tlv *vdp;int role; LIST_HEAD(profile_head, vsi_profile) profile_head;
@@ -129,7 +131,7 @@ struct vdp_user_data {struct lldp_module *vdp_register (void );void vdp_unregister (struct lldp_module *mod);struct vdp_data *vdp_data (char *ifname); -struct packed_tlv *vdp_gettlv (struct port *port,struct vsi_profile *profile); +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);
@@ -142,12 +144,12 @@ struct vsi_profile *vdp_add_profile(struct vsi_profile *profile); c =sprintf (s,"response: %i\n" , p->response); s += c; \ c =sprintf (s,"state: %i\n" , p->state); s += c; \ c =sprintf (s,"mgrid: %i\n" , p->mgrid); s += c; \ - c =sprintf (s,"id: %x%x%x\n" , p->id[2 ], p->id[1 ], p->id[0 ]); \ + c =sprintf (s,"id: %x\n" , p->id); \ s += c; \ c =sprintf (s,"version: %i\n" , p->version); s += c; \char instance[INSTANCE_STRLEN +2 ]; \instance2str (p->instance, instance,sizeof (instance)); \ - c =sprintf (s,"instance: %s\n" , &instance); s += c; \ + c =sprintf (s,"instance: %s\n" , &instance[0 ]); s += c; \char macbuf[MAC_ADDR_STRLEN +1 ]; \mac2str (p->mac, macbuf,MAC_ADDR_STRLEN ); \ c =sprintf (s,"mac: %s\n" , macbuf); s += c; \
lldp/ports.h +0 -14
@@ -136,19 +136,6 @@ struct porttlvs{struct unpacked_tlv *last_peer; }; -struct ecp { -struct l2_packet_data *l2; -int sequence; -int retries; -int ackReceived; -int ackTimerExpired; -u16 lastSequence; -u16 seqECPDU; -struct portrx rx; -struct porttx tx; -struct portstats stats; -}; -struct port {char *ifname;u8 hw_resetting;
@@ -169,7 +156,6 @@ struct port {/* not sure */ struct porttlvs tlvs; -struct ecp ecp;struct port *next; };
lldp_vdp.c new file +1140 -0
1,140 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
Re: [E1000-eedc] [PATCH 05/10] implementation of VDP
Quoted 35 lines · Jens Osterkamp
This patch contains an initial implemention of VDP as specified in IEEE 802.1Qbg.
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.
Signed-off-by Jens Osterkamp <[email protected]>--- Makefile.am | 8 +- ecp/ecp.c | 22 +- ecp/ecp.h | 19 +- ecp/ecp_rx.c | 350 ++++++++-------- ecp/ecp_tx.c | 292 ++++++++------ include/lldp.h | 1 + include/lldp_vdp.h | 10 +- lldp/ports.h | 14 - lldp_vdp.c | 1140 ++++++++++++++++++++++++++++++++++++++++++++++++++++ lldpad.c | 2 + 10 files changed, 1517 insertions(+), 341 deletions(-) create mode 100644 lldp_vdp.c
snip
Quoted 104 lines
/*
ecp_build_ECPDU- create an ecp protocol data unit
- * @port: currently used port
+ * @vd: currently used port
* @mode: mode to create pdu with (REQ or ACK) *
* returns true on success, false on failureecp/ecp_tx.c +40
-15@@ -86,7 +88,7 @@ void ecp_print_frameout(struct port *port)* or ACK mode, plus a list of packed TLVs created from the profiles on this * port. */ -bool ecp_build_ECPDU (struct port *port,int mode) +bool ecp_build_ECPDU (struct vdp_data *vd,int mode) {struct l2_ethhdr eth;struct ecp_hdr ecp_hdr;@@ -94,28 +96,26 @@ bool ecp_build_ECPDU(struct port *port, int mode)u32 fb_offset =0 ;u32 datasize =0 ;struct packed_tlv *ptlv =NULL ; -struct lldp_module *np; -struct vdp_data *vd;struct vsi_profile *p; -if (port->ecp.tx.frameout) { -free (port->ecp.tx.frameout); - port->ecp.tx.frameout =NULL ; +if (vd->ecp.tx.frameout) { +free (vd->ecp.tx.frameout); + vd->ecp.tx.frameout =NULL ; }/* TODO: different multicast address for sending ECP over S-channel (multi_cast_source_s) * S-channels to implement later */ memcpy (eth.h_dest, multi_cast_source,ETH_ALEN ); -l2_packet_get_own_src_addr (port->ecp.l2,(u8 *)&own_addr); +l2_packet_get_own_src_addr (vd->ecp.l2,(u8 *)&own_addr);memcpy (eth.h_source, &own_addr,ETH_ALEN ); eth.h_proto =htons (ETH_P_ECP ); - port->ecp.tx.frameout = (u8 *)malloc (ETH_FRAME_LEN ); -if (port->ecp.tx.frameout ==NULL ) { + vd->ecp.tx.frameout = (u8 *)malloc (ETH_FRAME_LEN ); +if (vd->ecp.tx.frameout ==NULL ) {printf ("InfoECPDU: Failed to malloc frame buffer \n" );return false; } -memset (port->ecp.tx.frameout,0 ,ETH_FRAME_LEN ); -memcpy (port->ecp.tx.frameout, (void *)ð,sizeof (struct l2_ethhdr )); +memset (vd->ecp.tx.frameout,0 ,ETH_FRAME_LEN ); +memcpy (vd->ecp.tx.frameout, (void *)ð,sizeof (struct l2_ethhdr )); fb_offset +=sizeof (struct l2_ethhdr ); ecp_hdr.oui[0 ] =0x0 ;@@ -134,111 +134,140 @@ bool ecp_build_ECPDU(struct port *port, int mode)break ;default :printf ("%s(%i): unknown mode for %s !\n" , __func__, __LINE__, - port->ifname); + vd->ifname); } - ecp_hdr.seqnr = port->ecp.lastSequence; + ecp_hdr.seqnr = vd->ecp.lastSequence;if ((sizeof (struct ecp_hdr )+fb_offset) >ETH_MAX_DATA_LEN ) goto error; -memcpy (port->ecp.tx.frameout+fb_offset, (void *)&ecp_hdr,sizeof (struct ecp_hdr )); +memcpy (vd->ecp.tx.frameout+fb_offset, (void *)&ecp_hdr,sizeof (struct ecp_hdr )); datasize +=sizeof (struct ecp_hdr ); fb_offset +=sizeof (struct ecp_hdr ); -/* TODO: create tlvs from profiles here */ +/* create packed_tlvs for all profiles on this interface */ + LIST_FOREACH(p, &vd->profile_head, profile) { +if (!p) { +printf ("%s(%i): list vd->profile_head empty !\n" , __func__, __LINE__); +continue ; + } + +if (p->localChange != mode) { +printf ("%s(%i): not sending out profile !\n" , __func__, __LINE__); +continue ; + } + + ptlv =vdp_gettlv (vd, p); + +if (!ptlv) { +printf ("%s(%i): ptlv not created !\n" , __func__, __LINE__); +continue ; + } + +if (ptlv) { +if ((ptlv->size+fb_offset) >ETH_MAX_DATA_LEN ) + goto error; +memcpy (vd->ecp.tx.frameout+fb_offset, + ptlv->tlv, ptlv->size); + datasize += ptlv->size; + fb_offset += ptlv->size; + } + }/* The End TLV marks the end of the LLDP PDU */ ptlv =pack_end_tlv ();if (!ptlv || ((ptlv->size + fb_offset) >ETH_MAX_DATA_LEN ))
ecp/ecp_tx.c bool ecp_build_ECPDU(struct port *port, int mode) · line 187
Quoted 10 lines
ecp/ecp_tx.c +2
-2goto error; -memcpy (port->ecp.tx.frameout + fb_offset, ptlv->tlv, ptlv->size); +memcpy (vd->ecp.tx.frameout + fb_offset, ptlv->tlv, ptlv->size); datasize += ptlv->size; fb_offset += ptlv->size; ptlv =free_pkd_tlv (ptlv);if (datasize <ETH_MIN_DATA_LEN ) - port->ecp.tx.sizeout =ETH_MIN_PKT_LEN ; + vd->ecp.tx.sizeout =ETH_MIN_PKT_LEN ;
check ETH_MAX_DATA_LEN here as well as min length.
Quoted 1,036 lines
ecp/ecp_tx.c +105
-106else - port->ecp.tx.sizeout = fb_offset; + vd->ecp.tx.sizeout = fb_offset;return true; error: ptlv =free_pkd_tlv (ptlv); -if (port->ecp.tx.frameout) -free (port->ecp.tx.frameout); - port->ecp.tx.frameout =NULL ; +if (vd->ecp.tx.frameout) +free (vd->ecp.tx.frameout); + vd->ecp.tx.frameout =NULL ;printf ("InfoECPDU: packed TLV too large for tx frame\n" );return false; }/* ecp_tx_Initialize - initializes the ecp tx state machine -* @port: currently used port +* @vd: currently used port * * no return value * * initializes some variables for the ecp tx state machine. */ -void ecp_tx_Initialize (struct port *port) +void ecp_tx_Initialize (struct vdp_data *vd) { -if (port->ecp.tx.frameout) { -free (port->ecp.tx.frameout); - port->ecp.tx.frameout =NULL ; +if (vd->ecp.tx.frameout) { +free (vd->ecp.tx.frameout); + vd->ecp.tx.frameout =NULL ; } - port->ecp.tx.localChange =VDP_PROFILE_REQ ; - port->ecp.lastSequence =ECP_SEQUENCE_NR_START ; - port->ecp.stats.statsFramesOutTotal =0 ; - port->ecp.ackTimerExpired = false; - port->ecp.retries =0 ; -l2_packet_get_port_state (port->ecp.l2, (u8 *)&(port->portEnabled)); + vd->ecp.tx.localChange =VDP_PROFILE_REQ ; + vd->ecp.lastSequence =ECP_SEQUENCE_NR_START ; + vd->ecp.stats.statsFramesOutTotal =0 ; + vd->ecp.ackTimerExpired = false; + vd->ecp.retries =0 ; + +struct port *port =port_find_by_name (vd->ifname); +l2_packet_get_port_state (vd->ecp.l2, (u8 *)&(port->portEnabled));return ; }/* ecp_txFrame - transmit ecp frame -* @port: currently used port +* @vd: currently used port * * returns the number of characters sent on success, -1 on failure * * sends out the frame stored in the frameout structure using l2_packet_send. */ -u8 ecp_txFrame (struct port *port) +u8 ecp_txFrame (struct vdp_data *vd) {int status =0 ; - status =l2_packet_send (port->ecp.l2, (u8 *)&multi_cast_source, -htons (ETH_P_ECP ),port->ecp.tx.frameout,port->ecp.tx.sizeout); - port->ecp.stats.statsFramesOutTotal++; + status =l2_packet_send (vd->ecp.l2, (u8 *)&multi_cast_source, +htons (ETH_P_ECP ),vd->ecp.tx.frameout,vd->ecp.tx.sizeout); + vd->ecp.stats.statsFramesOutTotal++;return status; }/* ecp_tx_create_frame - create ecp frame -* @port: currently used port +* @vd: currently used port * * no return value * * */ -void ecp_tx_create_frame (struct port *port) +void ecp_tx_create_frame (struct vdp_data *vd) {/* send REQs */ -if (port->ecp.tx.localChange &VDP_PROFILE_REQ ) { -printf ("%s(%i)-%s: sending REQs\n" , __func__, __LINE__, port->ifname); -ecp_build_ECPDU (port,VDP_PROFILE_REQ ); -ecp_print_frameout (port); -ecp_txFrame (port); +if (vd->ecp.tx.localChange &VDP_PROFILE_REQ ) { +printf ("%s(%i)-%s: sending REQs\n" , __func__, __LINE__, vd->ifname); +ecp_build_ECPDU (vd,VDP_PROFILE_REQ ); +ecp_print_frameout (vd); +ecp_txFrame (vd); }/* send ACKs */ -if (port->ecp.tx.localChange &VDP_PROFILE_ACK ) { -printf ("%s(%i)-%s: sending ACKs\n" , __func__, __LINE__, port->ifname); -ecp_build_ECPDU (port,VDP_PROFILE_ACK ); -ecp_print_frameout (port); -ecp_txFrame (port); +if (vd->ecp.tx.localChange &VDP_PROFILE_ACK ) { +printf ("%s(%i)-%s: sending ACKs\n" , __func__, __LINE__, vd->ifname); +ecp_build_ECPDU (vd,VDP_PROFILE_ACK ); +ecp_print_frameout (vd); +ecp_txFrame (vd); } - port->ecp.tx.localChange =0 ; + vd->ecp.tx.localChange =0 ;return ; }@@ -253,32 +282,32 @@ void ecp_tx_create_frame(struct port *port)*/ static void ecp_tx_timeout_handler (void *eloop_data,void *user_ctx) { -struct port *port; +struct vdp_data *vd; - port = (struct port *) user_ctx; + vd = (struct vdp_data *) user_ctx; - port->ecp.ackTimerExpired = true; + vd->ecp.ackTimerExpired = true;printf ("%s(%i)-%s: timer expired\n" , __func__, __LINE__, - port->ifname); + vd->ifname); -ecp_tx_run_sm (port); +ecp_tx_run_sm (vd); }/* ecp_tx_stop_ackTimer - stop the ECP ack timer -* @port: currently used port +* @vd: currently used port * * returns the number of removed handlers * * stops the ECP ack timer. used when a ack frame for the port has been * received. */ -static int ecp_tx_stop_ackTimer (struct port *port) +static int ecp_tx_stop_ackTimer (struct vdp_data *vd) {printf ("%s(%i)-%s: stopping timer\n" , __func__, __LINE__, - port->ifname); + vd->ifname); -return eloop_cancel_timeout (ecp_tx_timeout_handler,NULL , (void *) port); +return eloop_cancel_timeout (ecp_tx_timeout_handler,NULL , (void *) vd); }/* ecp_tx_start_ackTimer - starts the ECP ack timer @@ -288,23 +317,23 @@ static int ecp_tx_stop_ackTimer(struct port *port)* * starts the ack timer when a frame has been sent out. */ -static void ecp_tx_start_ackTimer (struct port *port) +static void ecp_tx_start_ackTimer (struct vdp_data *vd) {unsigned int secs, usecs; - port->ecp.ackTimerExpired = false; + vd->ecp.ackTimerExpired = false; secs =ECP_TRANSMISSION_TIMER /ECP_TRANSMISSION_DIVIDER ; usecs =ECP_TRANSMISSION_TIMER %ECP_TRANSMISSION_DIVIDER ;printf ("%s(%i)-%s: starting timer\n" , __func__, __LINE__, - port->ifname); + vd->ifname); -eloop_register_timeout (secs, usecs, ecp_tx_timeout_handler,NULL , (void *) port); +eloop_register_timeout (secs, usecs, ecp_tx_timeout_handler,NULL , (void *) vd); }/* ecp_tx_change_state - changes the ecp tx sm state -* @port: currently used port +* @vd: currently used port * @newstate: new state for the sm * * no return value @@ -312,39 +341,36 @@ static void ecp_tx_start_ackTimer(struct port *port)* checks state transistion for consistency and finally changes the state of * the profile. */ -static void ecp_tx_change_state (struct port *port,u8 newstate) +static void ecp_tx_change_state (struct vdp_data *vd,u8 newstate) {switch (newstate) { -case ECP_TX_IDLE : -break ;case ECP_TX_INIT_TRANSMIT : -assert (port->ecp.tx.state ==ECP_TX_IDLE );break ;case ECP_TX_TRANSMIT_ECPDU : -assert ((port->ecp.tx.state ==ECP_TX_INIT_TRANSMIT ) || - (port->ecp.tx.state ==ECP_TX_WAIT_FOR_ACK ) || - (port->ecp.tx.state ==ECP_TX_REQUEST_PDU )); +assert ((vd->ecp.tx.state ==ECP_TX_INIT_TRANSMIT ) || + (vd->ecp.tx.state ==ECP_TX_WAIT_FOR_ACK ) || + (vd->ecp.tx.state ==ECP_TX_REQUEST_PDU ));break ;case ECP_TX_WAIT_FOR_ACK : -assert (port->ecp.tx.state ==ECP_TX_TRANSMIT_ECPDU ); +assert (vd->ecp.tx.state ==ECP_TX_TRANSMIT_ECPDU );break ;case ECP_TX_REQUEST_PDU : -assert (port->ecp.tx.state ==ECP_TX_WAIT_FOR_ACK ); +assert (vd->ecp.tx.state ==ECP_TX_WAIT_FOR_ACK );break ;default :printf ("ERROR: The ECP_TX State Machine is broken!\n" ); -log_message (MSG_ERR_TX_SM_INVALID ,"%s" , port->ifname); +log_message (MSG_ERR_TX_SM_INVALID ,"%s" , vd->ifname); }printf ("%s(%i)-%s: state change %s -> %s\n" , __func__, __LINE__, - port->ifname, ecp_tx_states[port->ecp.tx.state], ecp_tx_states[newstate]); + vd->ifname, ecp_tx_states[vd->ecp.tx.state], ecp_tx_states[newstate]); - port->ecp.tx.state = newstate; + vd->ecp.tx.state = newstate;return ; }/* ecp_set_tx_state - sets the ecp tx sm state -* @port: currently used port +* @vd: currently used port * * returns true or false * @@ -352,116 +378,116 @@ static void ecp_tx_change_state(struct port *port, u8 newstate)* variables. returns true or false depending on wether the state machine * can be run again with the new state or can stop at the current state. */ -static bool ecp_set_tx_state (struct port *port) +static bool ecp_set_tx_state (struct vdp_data *vd) { +struct port *port =port_find_by_name (vd->ifname); + +if (!port) { +printf ("%s(%i): port not found !\n" , __func__, __LINE__); +return 0 ; + } +if ((port->portEnabled == false) && (port->prevPortEnabled == true)) {printf ("set_tx_state: port was disabled\n" ); -ecp_tx_change_state (port,ECP_TX_INIT_TRANSMIT ); +ecp_tx_change_state (vd,ECP_TX_INIT_TRANSMIT ); } port->prevPortEnabled = port->portEnabled; -switch (port->ecp.tx.state) { -case ECP_TX_IDLE : -if (port->portEnabled) { -ecp_tx_change_state (port,ECP_TX_INIT_TRANSMIT ); -return true; - } -return false; +switch (vd->ecp.tx.state) {case ECP_TX_INIT_TRANSMIT :if (port->portEnabled && ((port->adminStatus == enabledRxTx) || (port->adminStatus == enabledTxOnly))) { -ecp_tx_change_state (port,ECP_TX_TRANSMIT_ECPDU ); +ecp_somethingChangedLocal (vd,VDP_PROFILE_REQ ); +ecp_tx_change_state (vd,ECP_TX_TRANSMIT_ECPDU );return true; }return false;case ECP_TX_TRANSMIT_ECPDU :if ((port->adminStatus == disabled) || (port->adminStatus == enabledRxOnly)) { -ecp_tx_change_state (port,ECP_TX_INIT_TRANSMIT ); +ecp_tx_change_state (vd,ECP_TX_INIT_TRANSMIT );return true; } -ecp_tx_change_state (port,ECP_TX_WAIT_FOR_ACK ); +ecp_tx_change_state (vd,ECP_TX_WAIT_FOR_ACK );return true;case ECP_TX_WAIT_FOR_ACK : -if (port->ecp.ackTimerExpired) { - port->ecp.retries++; -if (port->ecp.retries <ECP_MAX_RETRIES ) { -ecp_somethingChangedLocal (port,VDP_PROFILE_REQ ); -ecp_tx_change_state (port,ECP_TX_TRANSMIT_ECPDU ); +if (vd->ecp.ackTimerExpired) { + vd->ecp.retries++; +if (vd->ecp.retries <ECP_MAX_RETRIES ) { +ecp_somethingChangedLocal (vd,VDP_PROFILE_REQ ); +ecp_tx_change_state (vd,ECP_TX_TRANSMIT_ECPDU );return true; } -if (port->ecp.retries ==ECP_MAX_RETRIES ) { +if (vd->ecp.retries ==ECP_MAX_RETRIES ) {printf ("%s(%i)-%s: 1 \n" , __func__, __LINE__, - port->ifname); -ecp_tx_change_state (port,ECP_TX_REQUEST_PDU ); + vd->ifname); +ecp_tx_change_state (vd,ECP_TX_REQUEST_PDU );return true; } } -if (port->ecp.ackReceived && port->ecp.seqECPDU == port->ecp.lastSequence) { - port->ecp.ackReceived = false; -ecp_tx_change_state (port,ECP_TX_REQUEST_PDU ); +if (vd->ecp.ackReceived && vd->ecp.seqECPDU == vd->ecp.lastSequence) { + vd->ecp.ackReceived = false; +ecp_tx_change_state (vd,ECP_TX_REQUEST_PDU );return true; }return false;case ECP_TX_REQUEST_PDU : -if (port->ecp.tx.localChange &VDP_PROFILE_REQ ) { -ecp_tx_change_state (port,ECP_TX_TRANSMIT_ECPDU ); +if (vd->ecp.tx.localChange &VDP_PROFILE_REQ ) { +ecp_tx_change_state (vd,ECP_TX_TRANSMIT_ECPDU );return true; }return false;default :printf ("ERROR: The TX State Machine is broken!\n" ); -log_message (MSG_ERR_TX_SM_INVALID ,"%s" , port->ifname); +log_message (MSG_ERR_TX_SM_INVALID ,"%s" , vd->ifname);return false; } }/* ecp_tx_run_sm - state machine for ecp tx -* @port: currently used port +* @vd: currently used vdp_data * * no return value * * runs the state machine for ecp tx. */ -void ecp_tx_run_sm (struct port *port) +void ecp_tx_run_sm (struct vdp_data *vd) {do {printf ("%s(%i)-%s: ecp_tx - %s\n" , __func__, __LINE__, - port->ifname, ecp_tx_states[port->ecp.tx.state]); + vd->ifname, ecp_tx_states[vd->ecp.tx.state]); -switch (port->ecp.tx.state) { -case ECP_TX_IDLE : -break ; +switch (vd->ecp.tx.state) {case ECP_TX_INIT_TRANSMIT : -ecp_tx_Initialize (port); +ecp_tx_Initialize (vd);break ;case ECP_TX_TRANSMIT_ECPDU : -ecp_tx_create_frame (port); -ecp_tx_start_ackTimer (port); +ecp_tx_create_frame (vd); +ecp_tx_start_ackTimer (vd);break ;case ECP_TX_WAIT_FOR_ACK : -if (port->ecp.ackReceived) { +if (vd->ecp.ackReceived) {printf ("%s(%i)-%s: ECP_TX_WAIT_FOR_ACK ackReceived\n" , __func__, __LINE__, - port->ifname); + vd->ifname);printf ("%s(%i)-%s: 2: seqECPDU %x lastSequence %x \n" , __func__, __LINE__, - port->ifname, port->ecp.seqECPDU, port->ecp.lastSequence); - port->ecp.tx.localChange =0 ; -ecp_tx_stop_ackTimer (port); -ecp_rx_ProcessFrame (port); + vd->ifname, vd->ecp.seqECPDU, vd->ecp.lastSequence); + vd->ecp.tx.localChange =0 ; +ecp_tx_stop_ackTimer (vd); +ecp_rx_ProcessFrame (vd); }break ;case ECP_TX_REQUEST_PDU : - port->ecp.retries =0 ; - port->ecp.lastSequence++; + vd->ecp.retries =0 ; + vd->ecp.lastSequence++;printf ("%s(%i)-%s: ECP_TX_REQUEST_PDU lastSequence %x\n" , __func__, __LINE__, - port->ifname, port->ecp.lastSequence++); + vd->ifname, vd->ecp.lastSequence++);break ;default :printf ("%s(%i): ERROR The TX State Machine is broken!\n" , __func__, __LINE__); -log_message (MSG_ERR_TX_SM_INVALID ,"%s" , port->ifname); +log_message (MSG_ERR_TX_SM_INVALID ,"%s" , vd->ifname); } - }while (ecp_set_tx_state (port) == true); + }while (ecp_set_tx_state (vd) == true);return ; }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_vdp.h +6
-4@@ -27,6 +27,7 @@#define _LLDP_VDP_H#include "lldp_mod.h" +#include "ecp/ecp.h" #define LLDP_MOD_VDP OUI_IEEE_8021Qbg+1@@ -101,7 +102,7 @@ struct vsi_profile {int mode;int response;u8 mgrid; -u8 id[3 ]; +int id;u8 version;u8 instance[16 ];u8 mac[6 ];/* TODO: currently only one MAC/VLAN pair supported, more later */ @@ -116,6 +117,7 @@ struct vsi_profile {struct vdp_data {char ifname[IFNAMSIZ ]; +struct ecp ecp;struct unpacked_tlv *vdp;int role; LIST_HEAD(profile_head, vsi_profile) profile_head;@@ -129,7 +131,7 @@ struct vdp_user_data {struct lldp_module *vdp_register (void );void vdp_unregister (struct lldp_module *mod);struct vdp_data *vdp_data (char *ifname); -struct packed_tlv *vdp_gettlv (struct port *port,struct vsi_profile *profile); +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);@@ -142,12 +144,12 @@ struct vsi_profile *vdp_add_profile(struct vsi_profile *profile); c =sprintf (s,"response: %i\n" , p->response); s += c; \ c =sprintf (s,"state: %i\n" , p->state); s += c; \ c =sprintf (s,"mgrid: %i\n" , p->mgrid); s += c; \ - c =sprintf (s,"id: %x%x%x\n" , p->id[2 ], p->id[1 ], p->id[0 ]); \ + c =sprintf (s,"id: %x\n" , p->id); \ s += c; \ c =sprintf (s,"version: %i\n" , p->version); s += c; \char instance[INSTANCE_STRLEN +2 ]; \instance2str (p->instance, instance,sizeof (instance)); \ - c =sprintf (s,"instance: %s\n" , &instance); s += c; \ + c =sprintf (s,"instance: %s\n" , &instance[0 ]); s += c; \char macbuf[MAC_ADDR_STRLEN +1 ]; \mac2str (p->mac, macbuf,MAC_ADDR_STRLEN ); \ c =sprintf (s,"mac: %s\n" , macbuf); s += c; \lldp/ports.h +0
-14@@ -136,19 +136,6 @@ struct porttlvs{struct unpacked_tlv *last_peer; }; -struct ecp { -struct l2_packet_data *l2; -int sequence; -int retries; -int ackReceived; -int ackTimerExpired; -u16 lastSequence; -u16 seqECPDU; -struct portrx rx; -struct porttx tx; -struct portstats stats; -}; -struct port {char *ifname;u8 hw_resetting;@@ -169,7 +156,6 @@ struct port {/* not sure */ struct porttlvs tlvs; -struct ecp ecp;struct port *next; };lldp_vdp.c new file +530
-0@@ -0,0 +1,1140 @@ +/******************************************************************************* + +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". + +*******************************************************************************/ + +#include <net/if.h> +#include <sys/queue.h> +#include <sys/socket.h> +#include <sys/ioctl.h> +#include <sys/utsname.h> +#include <linux/if_bridge.h> +#include "lldp.h" +#include "lldp_vdp.h" +#include "ecp/ecp.h" +#include "eloop.h" +#include "lldp_evb.h" +#include "messages.h" +#include "config.h" +#include "common.h" +#include "lldp_vdp_clif.h" +#include "lldp_vdp_cmds.h" + +/* vdp_data - searches vdp_data in the list of modules for this port +* @ifname: interface name to search for +* +* returns vdp_data on success, NULL on error +* +* searches the list of user_data for the VDP module user_data. +*/ +struct vdp_data *vdp_data (char *ifname) +{ +struct vdp_user_data *ud; +struct vdp_data *vd =NULL ; + + ud =find_module_user_data_by_if (ifname, &lldp_head,LLDP_MOD_VDP ); +if (ud) { + LIST_FOREACH(vd, &ud->head, entry) { +if (!strncmp (ifname, vd->ifname,IFNAMSIZ )) +return vd; + } + } +return NULL ; +} + +/* vdp_free_tlv - free tlv in vdp_data +* @vd: vdp_data +* +* no return value +* +* frees up tlv in vdp_data. used in vdp_free_data. +*/ +static void vdp_free_tlv (struct vdp_data *vd) +{ +if (vd) { +FREE_UNPKD_TLV (vd, vdp); + } +} + +/* vdp_free_data - frees up vdp data +* @ud: user data structure +* +* no return value +* +* removes vd_structure from the user_data list. frees up tlv in vdp_data. +* used in vdp_unregister. +*/ +static void vdp_free_data (struct vdp_user_data *ud) +{ +struct vdp_data *vd; +if (ud) { +while (!LIST_EMPTY (&ud->head)) { + vd =LIST_FIRST (&ud->head); +LIST_REMOVE (vd, entry); +vdp_free_tlv (vd); +free (vd); + } + } +} + +/* vdp_print_profile - print a vsi profile +* @profile: profile to print +* +* no return value +* +* 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) +{ +char *s, *t; + + s = t =malloc (VDP_BUF_SIZE ); + +if (!s) { +printf ("%s(%i): unable to allocate string !\n" , __func__, __LINE__); + } + +PRINT_PROFILE (t, profile); + +printf ("profile: %s\n" , s); + +free (s); +} + +/* vdp_somethingChangedLocal - set flag if profile has changed +* @profile: profile to set the flag for +* @mode: mode to set the flag to +* +* no return value +* +* set the localChange flag with a mode to indicate a profile has changed. +* used next time when a ecpdu with profiles is sent out. +*/ +void vdp_somethingChangedLocal (struct vsi_profile *profile,int mode) +{ + profile->localChange = mode; +} + +/* vdp_ackTimer_expired - checks for expired ack timer +* @profile: profile to be checked +* +* returns true or false +* +* returns value of profile->ackTimerExpired, true if ack timer has expired, +* false otherwise. +*/ +static bool vdp_ackTimer_expired (struct vsi_profile *profile) +{ +return profile->ackTimerExpired; +} + +/* vdp_timeout_handler - handles the ack timer expiry +* @eloop_data: data structure of event loop +* @user_ctx: user context, profile here +* +* no return value +* +* called when the VDP ack timer has expired. sets a flag and calls the VDP +* state machine. +*/ +void vdp_timeout_handler (void *eloop_data,void *user_ctx) +{ +struct vsi_profile *profile; + + profile = (struct vsi_profile *) user_ctx; + + profile->ackTimerExpired = true; + +printf ("%s(%i)-%s: timer expired\n" , __func__, __LINE__, + profile->port->ifname); + +vdp_vsi_sm_station (profile); +} + +/* vdp_stop_ackTimer - stop the VDP ack timer +* @profile: profile to process +* +* returns the number of removed handlers +* +* stops the VDP ack timer. used when a ack frame for the profile has been +* received. +*/ +static int vdp_stop_ackTimer (struct vsi_profile *profile) +{ +printf ("%s(%i)-%s: stopping timer\n" , __func__, __LINE__, + profile->port->ifname); + +return eloop_cancel_timeout (vdp_timeout_handler,NULL , (void *) profile); +} + +/* vdp_start_ackTimer - starts the VDP ack timer +* @profile: profile to process +* +* returns 0 on success, -1 on error +* +* starts the ack timer when a frame has been sent out. +*/ +static int vdp_start_ackTimer (struct vsi_profile *profile) +{ +unsigned int secs, usecs; + + profile->ackTimerExpired = false; + + secs =VDP_TRANSMISSION_TIMER /VDP_TRANSMISSION_DIVIDER ; + usecs =VDP_TRANSMISSION_TIMER %VDP_TRANSMISSION_DIVIDER ; + +printf ("%s(%i)-%s: starting timer\n" , __func__, __LINE__, + profile->port->ifname); + +return eloop_register_timeout (secs, usecs, vdp_timeout_handler,NULL , (void *) profile); +} + +/* vdp_vsi_change_station_state - changes the VDP station sm state +* @profile: profile to process +* @newstate: new state for the sm +* +* no return value +* +* actually changes the state of the profile +*/ +void vdp_vsi_change_station_state (struct vsi_profile *profile,u8 newstate) +{ +switch (newstate) { +case VSI_UNASSOCIATED : +break ; +case VSI_ASSOC_PROCESSING : +assert ((profile->state ==VSI_PREASSOCIATED ) || + (profile->state ==VSI_UNASSOCIATED )); +break ; +case VSI_ASSOCIATED : +assert (profile->state ==VSI_ASSOC_PROCESSING ); +break ; +case VSI_PREASSOC_PROCESSING : +assert (profile->state ==VSI_UNASSOCIATED ); +break ; +case VSI_PREASSOCIATED : +assert (profile->state ==VSI_PREASSOC_PROCESSING ); +break ; +case VSI_DEASSOC_PROCESSING : +assert ((profile->state ==VSI_PREASSOCIATED ) || + (profile->state ==VSI_ASSOCIATED )); +break ; +case VSI_EXIT : +assert ((profile->state ==VSI_ASSOC_PROCESSING ) || + (profile->state ==VSI_PREASSOC_PROCESSING ) || + (profile->state ==VSI_DEASSOC_PROCESSING ) || + (profile->state ==VSI_PREASSOCIATED ) || + (profile->state ==VSI_ASSOCIATED )); +break ; +default : +printf ("ERROR: The VDP station State Machine is broken!\n" ); +break ; + } + +printf ("%s(%i)-%s: state change %s -> %s\n" , __func__, __LINE__, + profile->port->ifname, vsi_states[profile->state], vsi_states[newstate]); + + profile->state = newstate; +} + +/* vdp_vsi_set_station_state - sets the vdp sm station state +* @profile: profile to process +* +* returns true or false +* +* switches the state machine to the next state depending on the input +* variables. returns true or false depending on wether the state machine +* can be run again with the new state or can stop at the current state. +*/ +static bool vdp_vsi_set_station_state (struct vsi_profile *profile) +{ +switch (profile->state) { +case VSI_UNASSOCIATED : +if ((profile->mode ==VDP_MODE_PREASSOCIATE ) || + (profile->mode ==VDP_MODE_PREASSOCIATE_WITH_RR )) { +vdp_vsi_change_station_state (profile,VSI_PREASSOC_PROCESSING ); +return true; + }else if (profile->mode ==VDP_MODE_ASSOCIATE ) { +vdp_vsi_change_station_state (profile,VSI_ASSOC_PROCESSING ); +return true; + } +return false; +case VSI_ASSOC_PROCESSING : +if (profile->ackReceived) { +vdp_vsi_change_station_state (profile,VSI_ASSOCIATED ); +return true; + }else if (!profile->ackReceived &&vdp_ackTimer_expired (profile)) { +vdp_vsi_change_station_state (profile,VSI_EXIT ); +return true; + } +return false; +case VSI_ASSOCIATED : +if (profile->mode ==VDP_MODE_PREASSOCIATE ) { +vdp_vsi_change_station_state (profile,VSI_PREASSOC_PROCESSING ); +return true; + }else if (profile->mode ==VDP_MODE_DEASSOCIATE ) { +vdp_vsi_change_station_state (profile,VSI_DEASSOC_PROCESSING ); +return true; + } +return false; +case VSI_PREASSOC_PROCESSING : +if (profile->ackReceived) { +vdp_vsi_change_station_state (profile,VSI_PREASSOCIATED ); +return true; + }else if (vdp_ackTimer_expired (profile)) { +vdp_vsi_change_station_state (profile,VSI_EXIT ); +return true; + } +case VSI_PREASSOCIATED : +if (profile->mode ==VDP_MODE_DEASSOCIATE ) { +vdp_vsi_change_station_state (profile,VSI_DEASSOC_PROCESSING ); +return true; + } +if (profile->mode ==VDP_MODE_ASSOCIATE ) { +vdp_vsi_change_station_state (profile,VSI_ASSOC_PROCESSING ); +return true; + } +return false; +case VSI_DEASSOC_PROCESSING : +if ((profile->ackReceived) ||vdp_ackTimer_expired (profile)) { +vdp_vsi_change_station_state (profile,VSI_EXIT ); +return true; + } +return false; +case VSI_EXIT : +return false; +default : +printf ("ERROR: The VSI RX State Machine is broken!\n" ); +log_message (MSG_ERR_RX_SM_INVALID ,"" ); +return false; + } +} + +/* vdp_vsi_sm_station - state machine for vdp station role +* @profile: profile for which the state is processed +* +* no return value +* +* runs the state machine for the station role of VDP. +*/ +void vdp_vsi_sm_station (struct vsi_profile *profile) +{ +struct vdp_data *vd =vdp_data (profile->port->ifname); + +vdp_vsi_set_station_state (profile); +do { +printf ("%s(%i)-%s: station - %s\n" , __func__, __LINE__, + profile->port->ifname, vsi_states[profile->state]); + +switch (profile->state) { +case VSI_UNASSOCIATED : +break ; +case VSI_ASSOC_PROCESSING : +vdp_somethingChangedLocal (profile,VDP_PROFILE_REQ ); +ecp_somethingChangedLocal (vd,VDP_PROFILE_REQ ); +ecp_tx_run_sm (vd); +vdp_start_ackTimer (profile); +break ; +case VSI_ASSOCIATED : +vdp_stop_ackTimer (profile); +/* TODO: +* vsiError = ProcRxandSetCfg(remoteTLV, localtlv, vsistate); +* if (!vsiError) vsistate=ASSOCIATED */ +break ; +case VSI_PREASSOC_PROCESSING : +/* send out profile */ +vdp_somethingChangedLocal (profile,VDP_PROFILE_REQ ); +ecp_somethingChangedLocal (vd,VDP_PROFILE_REQ ); +ecp_tx_run_sm (vd); +vdp_start_ackTimer (profile); +break ; +case VSI_PREASSOCIATED : + profile->ackReceived = false; +vdp_somethingChangedLocal (profile,VDP_PROFILE_NOCHANGE ); +vdp_stop_ackTimer (profile); +/* TODO vsiError = ProcRxandSetCfg(remoteTLV, localtlv, vsistate); +* if (!vsiError) vsistate=PREASSOCIATED */ +break ; +case VSI_DEASSOC_PROCESSING : +vdp_somethingChangedLocal (profile,VDP_PROFILE_REQ ); +vdp_start_ackTimer (profile); +break ; +case VSI_EXIT : +/* TODO: something went wrong, remove this profile */ +break ; +default : +printf ("ERROR: The VSI RX station State Machine is broken!\n" ); +log_message (MSG_ERR_TX_SM_INVALID ,"" ); + } + }while (vdp_vsi_set_station_state (profile) == true); + +} + +/* vdp_vsi_change_bridge_state - changes the VDP bridge sm state +* @profile: profile to process +* @newstate: new state for the sm +* +* no return value +* +* actually changes the state of the profile +*/ +static void vdp_vsi_change_bridge_state (struct vsi_profile *profile,u8 newstate) +{ +switch (newstate) { +case VSI_UNASSOCIATED : +break ; +case VSI_ASSOC_PROCESSING : +assert ((profile->state ==VSI_UNASSOCIATED ) || + (profile->state ==VSI_PREASSOCIATED ) || + (profile->state ==VSI_ASSOCIATED )); +break ; +case VSI_ASSOCIATED : +assert (profile->state ==VSI_ASSOC_PROCESSING ); +break ; +case VSI_PREASSOC_PROCESSING : +assert ((profile->state ==VSI_UNASSOCIATED ) || + (profile->state ==VSI_PREASSOCIATED ) || + (profile->state ==VSI_ASSOCIATED )); +break ; +case VSI_PREASSOCIATED : +assert (profile->state ==VSI_PREASSOC_PROCESSING ); +break ; +case VSI_DEASSOC_PROCESSING : +assert ((profile->state ==VSI_UNASSOCIATED ) || + (profile->state ==VSI_PREASSOCIATED ) || + (profile->state ==VSI_ASSOCIATED )); +break ; +case VSI_EXIT : +assert ((profile->state ==VSI_DEASSOC_PROCESSING ) || + (profile->state ==VSI_PREASSOC_PROCESSING ) || + (profile->state ==VSI_ASSOC_PROCESSING )); +break ; +default : +printf ("ERROR: The VDP bridge State Machine is broken!\n" ); +break ; + } + profile->state = newstate; +} + +/* vdp_vsi_set_bridge_state - sets the vdp sm bridge state +* @profile: profile to process +* +* returns true or false +* +* switches the state machine to the next state depending on the input +* variables. returns true or false depending on wether the state machine +* can be run again with the new state or can stop at the current state. +*/ +static bool vdp_vsi_set_bridge_state (struct vsi_profile *profile) +{ +switch (profile->state) { +case VSI_UNASSOCIATED : +if ((profile->mode ==VDP_MODE_DEASSOCIATE ))/* || (INACTIVE)) */ { +vdp_vsi_change_bridge_state (profile,VSI_DEASSOC_PROCESSING ); +return true; + }else if (profile->mode ==VDP_MODE_ASSOCIATE ) { +vdp_vsi_change_bridge_state (profile,VSI_ASSOC_PROCESSING ); +return true; + }else if (profile->mode ==VDP_MODE_PREASSOCIATE ) { +vdp_vsi_change_bridge_state (profile,VSI_PREASSOC_PROCESSING ); +return true; + } +return false; +case VSI_ASSOC_PROCESSING : +/* TODO: handle error case +if (!vsiError) || +(vsiError && vsiState == Assoc) { +*/ +if (profile->mode ==VDP_MODE_ASSOCIATE ) { +vdp_vsi_change_bridge_state (profile,VSI_ASSOCIATED ); +return true; + } +return false; +case VSI_ASSOCIATED : +if (profile->mode ==VDP_MODE_ASSOCIATE )/* || ( INACTIVE )*/ { +vdp_vsi_change_bridge_state (profile,VSI_DEASSOC_PROCESSING ); +return true; + }else if (profile->mode ==VDP_MODE_PREASSOCIATE ) { +vdp_vsi_change_bridge_state (profile,VSI_PREASSOC_PROCESSING ); +return true; + }else if (profile->mode ==VDP_MODE_ASSOCIATE ) { +vdp_vsi_change_bridge_state (profile,VSI_ASSOC_PROCESSING ); +return true; + } +return false; +case VSI_PREASSOC_PROCESSING : +if (profile->response !=VDP_RESPONSE_SUCCESS ) { +vdp_vsi_change_bridge_state (profile,VSI_EXIT ); +return true; + } +vdp_vsi_change_bridge_state (profile,VSI_PREASSOCIATED ); +return false; +case VSI_PREASSOCIATED : +if (profile->mode ==VDP_MODE_ASSOCIATE ) { +vdp_vsi_change_bridge_state (profile,VSI_ASSOC_PROCESSING ); +return true; + }else if (profile->mode ==VDP_MODE_DEASSOCIATE ) { +vdp_vsi_change_bridge_state (profile,VSI_DEASSOC_PROCESSING ); +return true; + }else if (profile->mode ==VDP_MODE_PREASSOCIATE ) { +vdp_vsi_change_bridge_state (profile,VSI_PREASSOC_PROCESSING ); +return true; + } +return false; +case VSI_DEASSOC_PROCESSING : +vdp_vsi_change_bridge_state (profile,VSI_EXIT ); +return false; +case VSI_EXIT : +return false; +default : +printf ("ERROR: The VSI RX State Machine (bridge) is broken!\n" ); +log_message (MSG_ERR_RX_SM_INVALID ,"" ); +return false; + } +} + +/* vdp_vsi_sm_bridge - state machine for vdp bridge role +* @profile: profile for which the state is processed +* +* no return value +* +* runs the state machine for the bridge role of VDP. +*/ +static void vdp_vsi_sm_bridge(struct vsi_profile *profile) +{ + struct vdp_data *vd = vdp_data(profile->port->ifname); + + vdp_vsi_set_bridge_state(profile); + do { + printf("%s(%i)-%s: bridge - %s\n", __func__, __LINE__,
lldp_vdp.c line 540
Quoted 10 lines
lldp_vdp.c new file +10
-0+ profile->port->ifname, vsi_states[profile->state]); +switch (profile->state) { +case VSI_UNASSOCIATED : +break ; +case VSI_ASSOC_PROCESSING : +/* TODO: vsiError = ProcRxandSetCfg(remoteTLV, localtlv, vsistate); +* if (vsiError) +* txTLV(Assoc NACK) +* else +* txTLV(Assoc ACK) */
*/
move the */ to a line on its own.
lldp_vdp.c line 549
Quoted 9 lines
lldp_vdp.c new file +9
-0+break ; +case VSI_ASSOCIATED : +break ; +case VSI_PREASSOC_PROCESSING : +/* TODO: vsiError = ProcRxandSetCfg(remoteTLV, localtlv, vsistate); +* if (vsiError) +* txTLV(PreAssoc NACK) +* else +* txTLV(PreAssoc ACK) */
same here.
Quoted 273 lines
lldp_vdp.c new file +273
-0+/* for now, we always succeed */ + profile->response =VDP_RESPONSE_SUCCESS ; +printf ("%s(%i)-%s: framein %p, sizein %i\n" , __func__, __LINE__, + profile->port->ifname, vd->ecp.rx.framein, + vd->ecp.rx.sizein); +ecp_rx_send_ack_frame (profile->port); +break ; +case VSI_PREASSOCIATED : +printf ("%s(%i)-%s: \n" , __func__, __LINE__, profile->port->ifname); +break ; +case VSI_DEASSOC_PROCESSING : +/* TODO: txTLV(DeAssoc ACK) */ +break ; +case VSI_EXIT : +/* TODO: something went wrong, remove this profile */ +break ; +default : +printf ("ERROR: The VSI RX bridge State Machine is broken!\n" ); +log_message (MSG_ERR_TX_SM_INVALID ,"" ); + } + }while (vdp_vsi_set_bridge_state (profile) == true); + +} + +/* +* vdp_print_vsi_tlv - print the raw contents of a VSI TLV +* @tlv: the unpacked tlv which gets printed +* +* No return value +* +* used for protocol debug purposes +*/ +static void vdp_print_vsi_tlv (struct unpacked_tlv *tlv) +{ +int i; + +printf ("### %s:type %i, length %i, info:\n" , __func__, tlv->type, tlv->length); + +for (i=0 ; i < tlv->length; i++) { +printf ("%02x " , tlv->info[i]); +if (!((i+1 ) %16 )) +printf ("\n" ); + } + +printf ("\n" ); +} + +/* +* vdp_validate_tlv - validates vsi tlvs +* @vdp: decoded vsi tlv +* +* Returns 0 on success, 1 on error +* +* checks the contents of an already decoded vsi tlv for inconsistencies +*/ +static int vdp_validate_tlv (struct tlv_info_vdp *vdp) +{ +if (ntoh24 (vdp->oui) != OUI_IEEE_8021Qbg) { +printf ("vdp->oui %06x \n" ,ntoh24 (vdp->oui)); + goto out_err; + } + +if (vdp->sub !=LLDP_VDP_SUBTYPE ) { +printf ("vdp->sub %02x \n" , vdp->sub); + goto out_err; + } + +if ((vdp->mode <VDP_MODE_PREASSOCIATE ) || + (vdp->mode >VDP_MODE_DEASSOCIATE )) { +printf ("Unknown mode %02x in vsi tlv !\n" , vdp->mode); + goto out_err; + } + +if ((vdp->response <VDP_RESPONSE_SUCCESS ) || + (vdp->response >VDP_RESPONSE_OUT_OF_SYNC )) { +printf ("Unknown response %02x \n" , vdp->response); + goto out_err; + } + +if (vdp->format !=VDP_MACVLAN_FORMAT_1 ) { +printf ("Unknown format %02x in vsi tlv !\n" , vdp->format); + goto out_err; + } + +if (ntohs (vdp->entries) !=1 ) { +printf ("Multiple entries %02x in vsi tlv !\n" , vdp->entries); + goto out_err; + } + +return 0 ; + +out_err: +return 1 ; +} + +/* +* vdp_indicate - receive VSI TLVs from ECP +* @port: the port on which the tlv was received +* @tlv: the unpacked tlv to receive +* @ecp_mode: the mode under which the tlv was received (ACK or REQ) +* +* Returns 0 on success +* +* receives a vsi tlv and creates a profile. Take appropriate action +* depending on the role of the (receive) port +*/ +int vdp_indicate (struct vdp_data *vd,struct unpacked_tlv *tlv,int ecp_mode) +{ +struct tlv_info_vdp *vdp; +struct vsi_profile *p, *profile; +struct port *port =port_find_by_name (vd->ifname); + +printf ("%s(%i): indicating vdp for for %s !\n" , __func__, __LINE__, vd->ifname); + +if (!port) { +printf ("%s(%i): port not found for %s !\n" , __func__, __LINE__, vd->ifname); + goto out_err; + } + + vdp =malloc (sizeof (struct tlv_info_vdp )); + +if (!vdp) { +printf ("%s(%i): unable to allocate vdp !\n" , __func__, __LINE__); + goto out_err; + } + +memset (vdp,0 ,sizeof (struct tlv_info_vdp )); +memcpy (vdp, tlv->info, tlv->length); + +if (vdp_validate_tlv (vdp)) { +printf ("%s(%i): Invalid TLV received !\n" , __func__, __LINE__); + goto out_err; + } + + profile =malloc (sizeof (struct vsi_profile )); + +if (!profile) { +printf ("%s(%i): unable to allocate profile !\n" , __func__, __LINE__); + goto out_vdp; + } + +memset (profile,0 ,sizeof (struct vsi_profile )); + + profile->mode = vdp->mode; + profile->response = vdp->response; + + profile->mgrid = vdp->mgrid; + profile->id =ntoh24 (vdp->id); + profile->version = vdp->version; +memcpy (&profile->instance, &vdp->instance,16 ); +memcpy (&profile->mac, &vdp->mac_vlan.mac,MAC_ADDR_LEN ); + profile->vlan =ntohs (vdp->mac_vlan.vlan); + + profile->port = port; +printf ("%s(%i):\n" , __func__, __LINE__); + +if (vd->role ==VDP_ROLE_STATION ) { +/* do we have the profile already ? */ + LIST_FOREACH(p, &vd->profile_head, profile) { +if (vdp_profile_equal (p, profile)) { +printf ("%s(%i): station: profile found, localChange %i ackReceived %i!\n" , + __func__, __LINE__, p->localChange, p->ackReceived); + +if (ecp_mode ==ECP_ACK ) + p->ackReceived = true; + +vdp_vsi_sm_station (p); + }else { +printf ("%s(%i): station: profile not found !\n" , __func__, __LINE__); +/* ignore profile */ + } + } + } + +if (vd->role ==VDP_ROLE_BRIDGE ) { +/* do we have the profile already ? */ + LIST_FOREACH(p, &vd->profile_head, profile) { +if (vdp_profile_equal (p, profile)) { +break ; + } + } + +if (p) { +printf ("%s(%i): bridge: profile found !\n" , __func__, __LINE__); + }else { +printf ("%s(%i): bridge: profile not found !\n" , __func__, __LINE__); +/* put it in the list */ + profile->state =VSI_UNASSOCIATED ; +LIST_INSERT_HEAD (&vd->profile_head, profile, profile ); + } + +vdp_vsi_sm_bridge (profile); + } + +return 0 ; + +out_vdp: +free (vdp); +out_err: +printf ("%s(%i): error !\n" , __func__, __LINE__); +return 1 ; + +} + +/* +* vdp_bld_vsi_tlv - build the VDP VSI TLV +* @vd: vdp_data structure for this port +* @profile: profile the vsi tlv is created from +* +* Returns 0 on success, ENOMEM otherwise +* +* creates a vdp structure from an existing profile +*/ +static int vdp_bld_vsi_tlv (struct vdp_data *vd,struct vsi_profile *profile) +{ +int rc =0 ; +struct unpacked_tlv *tlv =NULL ; +struct tlv_info_vdp vdp; + +FREE_UNPKD_TLV (vd, vdp); + +memset (&vdp,0 ,sizeof (vdp)); + +hton24 (vdp.oui, OUI_IEEE_8021Qbg); + vdp.sub =LLDP_VDP_SUBTYPE ; + vdp.mode = profile->mode; + vdp.response =0 ; + vdp.mgrid = profile->mgrid; +hton24 (vdp.id, profile->id); + vdp.version = profile->version; +memcpy (&vdp.instance,&profile->instance,16 ); + vdp.format =VDP_MACVLAN_FORMAT_1 ; + vdp.entries =htons (1 ); +memcpy (&vdp.mac_vlan.mac,&profile->mac,MAC_ADDR_LEN ); + vdp.mac_vlan.vlan =htons (profile->vlan); + + tlv =create_tlv (); +if (!tlv) + goto out_err; + + tlv->type =ORG_SPECIFIC_TLV ; + tlv->length =sizeof (vdp); + tlv->info = (u8 *)malloc (tlv->length); +if (!tlv->info) { +free (tlv); + tlv =NULL ; + rc =ENOMEM ; + goto out_err; + } +memcpy (tlv->info, &vdp, tlv->length); + + vd->vdp = tlv; + +out_err: +return rc; +} + +/* vdp_bld_tlv - builds a tlv from a profile +* @vd: vdp_data structure for this port +* @profile: profile the vsi tlv is created from +* +* returns 0 on success, != 0 on error +* +* wrapper function around vdp_bld_vsi_tlv. adds some checks and calls +* vdp_bld_vsi_tlv. +*/ + +static int vdp_bld_tlv (struct vdp_data *vd,struct vsi_profile *profile) +{ +int rc =0 ; + +if (!port_find_by_name (vd->ifname)) { + rc =EEXIST ;
lldp_vdp.c line 832
Quoted 10 lines
lldp_vdp.c new file +10
-0+ goto out_err; + } + +if (!init_cfg ()) { + rc =ENOENT ; + goto out_err; + } + +if (vdp_bld_vsi_tlv (vd, profile)) { + fprintf(stderr, "### %s:%s:vdp_bld_cfg_tlv() failed\n",
should be "vdp_bld_vsi_tlv failed".
Quoted 118 lines
lldp_vdp.c new file +118
-0+ __func__, vd->ifname); + rc =EINVAL ; + goto out_err_destroy; + } + +out_err_destroy: +destroy_cfg (); + +out_err: +return rc; +} + +/* vdp_gettlv - get the tlv for a profile +* @port: the port on which the tlv was received +* @profile: profile the vsi tlv is created from +* +* returns 0 on success +* +* this is the interface function called from ecp_build_ECPDU. It returns the +* packed tlv for a profile. +*/ +struct packed_tlv *vdp_gettlv (struct vdp_data *vd,struct vsi_profile *profile) +{ +int size; +struct packed_tlv *ptlv =NULL ; + +/* frees the unpacked_tlv in vdp_data +* also done in vdp_bld_vsi_tlv */ +vdp_free_tlv (vd); + +if (vdp_bld_tlv (vd, profile)) { +fprintf (stderr,"### %s:%s vdp_bld_tlv failed\n" , + __func__, vd->ifname); + goto out_err; + } + + size =TLVSIZE (vd->vdp); + +if (!size) { +printf ("%s(%i): size %i of unpacked_tlv not correct !\n" , __func__, __LINE__, + size); + goto out_err; + } + + ptlv =create_ptlv (); +if (!ptlv) + goto out_err; + + ptlv->tlv =malloc (size); +if (!ptlv->tlv) + goto out_free; + + ptlv->size =0 ; +PACK_TLV_AFTER (vd->vdp, ptlv, size, out_free); + +return ptlv; + +out_free: + ptlv =free_pkd_tlv (ptlv); +out_err: +fprintf (stderr,"### %s:%s: failed\n" , __func__, vd->ifname); +return NULL ; +} + +/* vdp_profile_equal - checks for equality of 2 profiles +* @p1: profile 1 +* @p2: profile 2 +* +* returns 1 on success, 0 on error +* +* compares mgrid, id, version, instance, mac and vlan of 2 profiles to find +* out if they are equal. +*/ +int vdp_profile_equal (struct vsi_profile *p1,struct vsi_profile *p2) +{ +if (p1->mgrid != p2->mgrid) +return 0 ; + +if (p1->id == p2->id) +return 0 ; + +if (p1->version != p2->version) +return 0 ; + +if (memcmp (p1->instance, p2->instance,16 )) +return 0 ; + +if (memcmp (p1->mac, p2->mac,MAC_ADDR_LEN )) +return 0 ; + +if (p1->vlan != p2->vlan) +return 0 ; + +return 1 ; +} + +/* vdp_add_profile - adds a profile to a per port list +* @profile: profile to add +* +* returns the profile that has been found or added +* +* main interface function which adds a profile to a list kept on a per-port +* basis. Checks if the profile is already in the list, adds it if necessary. +*/ +struct vsi_profile *vdp_add_profile (struct vsi_profile *profile) +{ +struct vsi_profile *p; +struct vdp_data *vd; + +printf ("%s(%i): adding vdp profile for %s !\n" , __func__, __LINE__, + profile->port->ifname); + + vd =vdp_data (profile->port->ifname); +if (!vd) { +printf ("%s(%i): Could not find vdp_data for %s !\n" , __func__, __LINE__, + profile->port->ifname); +return NULL ; + }
lldp_vdp.c line 960
Quoted 10 lines
lldp_vdp.c new file +10
-0+ +vdp_print_profile (profile); + +/* loop over all existing profiles and check wether +* one for this combination already exists. If yes, check, +* if the MAC/VLAN pair already exists. If not, add it. +* Note: currently only one MAC/VLAN pair supported ! */ + LIST_FOREACH(p, &vd->profile_head, profile) { +if (p) { +vdp_print_profile (p);
This is a lot of debug output.
lldp_vdp.c line 965
Quoted 5 lines
lldp_vdp.c new file +5
-0+if (vdp_profile_equal (p, profile)) { +if (p->mode == profile->mode) { +printf ("%s(%i): profile already exists, ignoring !\n" , + __func__, __LINE__); +return NULL ;
comment at top of function "return the profile that has been found or added" seems to indicate this should return the profile not NULL. I suspect a fix to the comment should suffice.
Quoted 27 lines
lldp_vdp.c new file +27
-0+ }else { +printf ("%s(%i): taking new mode !\n" , __func__, + __LINE__); + p->mode = profile->mode; +return p; + } + } + } + } + +LIST_INSERT_HEAD (&vd->profile_head, profile, profile ); + +return profile; +} + +/* vdp_ifdown - tear down vdp structures for a interface +* @ifname: name of the interface +* +* no return value +* +* interface function to lldpad. tears down vdp specific structures if +* interface "ifname" goes down. +*/ +void vdp_ifdown (char *ifname) +{ +struct vdp_data *vd; +struct vsi_profile *p;
lldp_vdp.c line 1002
Quoted 10 lines
lldp_vdp.c new file +10
-0+ + vd =vdp_data (ifname); +if (!vd) + goto out_err; + +LIST_REMOVE (vd, entry); + + LIST_FOREACH(p, &vd->profile_head, profile) { +free (p); +LIST_REMOVE (p, profile);
This is should be
LIST_REMOVE(p, profile);
free(p);
not the other way around.
lldp_vdp.c line 1009
Quoted 7 lines
lldp_vdp.c new file +7
-0+ } +vdp_free_tlv (vd); +free (vd); +fprintf (stderr,"### %s:port %s removed\n" , __func__, ifname); +return ; +out_err: +fprintf (stderr,"### %s:port %s adding failed\n" , __func__, ifname);
this is not adding a port and nothing failed the ifname has not been added.
Quoted 14 lines
lldp_vdp.c new file +14
-0+ +return ; +} + +/* vdp_ifup - build up vdp structures for a interface +* @ifname: name of the interface +* +* no return value +* +* interface function to lldpad. builds up vdp specific structures if +* interface "ifname" goes down. +*/ +void vdp_ifup (char *ifname) +{
lldp_vdp.c line 1033
Quoted 10 lines
lldp_vdp.c new file +10
-0+char *p; +struct vdp_data *vd; +struct vdp_user_data *ud; + +printf ("%s(%i): starting VDP for if %s !\n" , __func__, __LINE__, ifname); + + vd =vdp_data (ifname); +if (vd) { +fprintf (stderr,"%s:%s already exists\n" , __func__, ifname); + goto out_err;
This prints the error in out_err incorrectly.
lldp_vdp.c line 1037
Quoted 4 lines
lldp_vdp.c new file +4
-0+ } + +/* not found, alloc/init per-port module data */ + vd = (struct vdp_data *)calloc (1 ,sizeof (struct vdp_data ));
Use malloc instead of calloc() of one.
lldp_vdp.c line 1046
Quoted 9 lines
lldp_vdp.c new file +9
-0+if (!vd) { +fprintf (stderr,"### %s:%s malloc %ld failed\n" , + __func__, ifname,sizeof (*vd)); + goto out_err; + } +strncpy (vd->ifname, ifname,IFNAMSIZ ); + +if (!init_cfg ()) + goto out_err;
memory leak of 'vd' if init_cfg fails.
Quoted 107 lines
lldp_vdp.c new file +94
-0+ + vd->role =VDP_ROLE_STATION ; + +if (!get_cfg (ifname,"vdp.role" , (void *)&p, +CONFIG_TYPE_STRING )) { +if (!strcasecmp (p,VAL_BRIDGE )) { + vd->role =VDP_ROLE_BRIDGE ; + } + } + +printf ("%s: configured for %s mode !\n" , ifname, + (vd->role ==VDP_ROLE_BRIDGE ) ?"bridge" :"station" ); + +LIST_INIT (&vd->profile_head); + + ud =find_module_user_data_by_if (ifname, &lldp_head,LLDP_MOD_VDP ); +LIST_INSERT_HEAD (&ud->head, vd, entry); + +ecp_init (ifname); + +fprintf (stderr,"### %s:port %s added\n" , __func__, ifname); +return ; + +out_err: +fprintf (stderr,"### %s:port %s adding failed\n" , __func__, ifname); +return ; +} + +static const struct lldp_mod_ops vdp_ops = { + .lldp_mod_register = vdp_register, + .lldp_mod_unregister = vdp_unregister, + .lldp_mod_ifup = vdp_ifup, + .lldp_mod_ifdown = vdp_ifdown, + .get_arg_handler = vdp_get_arg_handlers, +}; + +/* vdp_register - register vdp module to lldpad +* @none +* +* returns lldp_module struct on success, NULL on error +* +* allocates a module structure with vdp module information and returns it +* to lldpad. +*/ +struct lldp_module *vdp_register (void ) +{ +struct lldp_module *mod; +struct vdp_user_data *ud; + + mod =malloc (sizeof (*mod)); +if (!mod) { +fprintf (stderr,"failed to malloc module data\n" ); +log_message (MSG_ERR_SERVICE_START_FAILURE , +"%s" ,"failed to malloc module data" ); + goto out_err; + } + ud =malloc (sizeof (struct vdp_user_data )); +if (!ud) { +free (mod); +fprintf (stderr,"failed to malloc module user data\n" ); +log_message (MSG_ERR_SERVICE_START_FAILURE , +"%s" ,"failed to malloc module user data" ); + goto out_err; + } +LIST_INIT (&ud->head); + mod->id =LLDP_MOD_VDP ; + mod->ops = &vdp_ops; + mod->data = ud; +fprintf (stderr,"### %s:done\n" , __func__); +return mod; + +out_err: +fprintf (stderr,"### %s:failed\n" , __func__); +return NULL ; +} + +/* vdp_unregister - unregister vdp module from lldpad +* @none +* +* no return value +* +* frees vdp module structure. +*/ +void vdp_unregister (struct lldp_module *mod) +{ +if (mod->data) { +vdp_free_data ((struct vdp_user_data *) mod->data); +free (mod->data); + } +free (mod); +fprintf (stderr,"### %s:done\n" , __func__); +} + +lldpad.c +1
-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"
lldpad.c struct lldp_module *(*register_tlv_table[])(void) = {
Quoted 8 lines
lldpad.c +1
-1@@ -65,6 +66,7 @@ struct lldp_module *(*register_tlv_table[])(void) = { med_register, ieee8023_register, evb_register, + vdp_register, NULL, }; --
Few minor nits otherwise looks good. Please merge relevant parts with patch 4 though.
Thanks!
John
Re: [E1000-eedc] [PATCH 05/10] implementation of VDP
Quoted 21 lines · John Fastabend
Quoted 20 lines · Jens Osterkamp
This patch contains an initial implemention of VDP as specified in IEEE 802.1Qbg.
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.
Signed-off-by Jens Osterkamp <[email protected]>
snip
Quoted 3 lines
Few minor nits otherwise looks good. Please merge relevant parts with patch 4 though.
I will address all your comments in my next posting of the series.
Thanks !
Jens
Signature · 5 lines
IBM Deutschland Research & Development GmbH Vorsitzender des Aufsichtsrats: Martin Jetter Geschäftsführung: Dirk Wittkopp Sitz der Gesellschaft: Böblingen Registergericht: Amtsgericht Stuttgart, HRB 243294
PATCH 6/10 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 | 394 +++++++++++++++++++++++++++++++++++++++++++++++ lldptool.c | 2 + 6 files changed, 622 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 +394 -0
394 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
Re: [E1000-eedc] [PATCH 06/10] VDP commandline interface
Quoted 213 lines · Jens Osterkamp
This 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.Signed-off-by Jens Osterkamp <[email protected]>--- Makefile.am | 12 +- include/lldp_vdp_clif.h | 39 +++++ include/lldp_vdp_cmds.h | 44 ++++++ lldp_vdp_clif.c | 136 ++++++++++++++++ lldp_vdp_cmds.c | 394 +++++++++++++++++++++++++++++++++++++++++++++++ lldptool.c | 2 + 6 files changed, 622 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.cMakefile.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.hinclude/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@@ -0,0 +1,44 @@ +/******************************************************************************* + +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_CMDS_H +#define _LLDP_VDP_CMDS_H + +struct arg_handlers *vdp_get_arg_handlers (); + +enum { +MODE =0 , +MGRID , +TYPEID , +TYPEIDVERSION , +INSTANCEID , +MAC , +VLAN , +}; + +#define VAL_STATION "station" +#define VAL_BRIDGE "bridge" + +#endif lldp_vdp_clif.c new file +42
-0@@ -0,0 +1,136 @@ +/******************************************************************************* + +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". + +*******************************************************************************/ + +#include "includes.h" +#include "common.h" +#include <stdio.h> +#include <syslog.h> +#include <sys/un.h> +#include <sys/stat.h> +#include "lldp_mod.h" +#include "lldptool.h" +#include "lldp.h" +#include "lldp_vdp.h" +#include "lldp_vdp_clif.h" + +void vdp_print_cfg_tlv (u16 ,char *info); +int vdp_print_help (); + +u32 vdp_lookup_tlv_name (char *tlvid_str); +
snip
Quoted 11 lines
lldp_vdp_clif.c new file +11
-0+ +static int get_arg_mode (struct cmd *cmd,char *arg,char *argvalue, +char *obuf) +{ +char *s, *t; +struct vsi_profile *np; +struct vdp_data *vd; + +if (cmd->cmd != cmd_gettlv) +return cmd_invalid; +
lldp_vdp_clif.c
Quoted 10 lines
lldp_vdp_clif.c new file +10
-0+switch (cmd->tlvid) { +case ((LLDP_MOD_VDP ) <<8 ) |LLDP_VDP_SUBTYPE : +break ; +case INVALID_TLVID : +return cmd_invalid; +default : +return cmd_not_applicable; + } + + s = t =malloc (VDP_BUF_SIZE );
memory leak on s or maybe I missed something.
Quoted 11 lines
lldp_vdp_clif.c new file +11
-0+if (!s) +return cmd_invalid; +memset (s,0 ,VDP_BUF_SIZE ); + + vd =vdp_data (cmd->ifname); +if (!vd) { +printf ("%s(%i): vdp_data for %s not found !\n" , __func__, __LINE__, + cmd->ifname); +return cmd_invalid; + } +
lldp_vdp_clif.c
Quoted 10 lines
lldp_vdp_clif.c new file +10
-0+ LIST_FOREACH(np, &vd->profile_head, profile) { +PRINT_PROFILE (t, np); + } + +sprintf (obuf,"%02x%s%04x%s" , (unsigned int )strlen (arg), arg, + (unsigned int )strlen (s), s); + +return cmd_success; +} +
Thanks,
John.
Re: [E1000-eedc] [PATCH 06/10] VDP commandline interface
Quoted 257 lines · John Fastabend
Quoted 213 lines · Jens Osterkamp
This 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.Signed-off-by Jens Osterkamp <[email protected]>--- Makefile.am | 12 +- include/lldp_vdp_clif.h | 39 +++++ include/lldp_vdp_cmds.h | 44 ++++++ lldp_vdp_clif.c | 136 ++++++++++++++++ lldp_vdp_cmds.c | 394 +++++++++++++++++++++++++++++++++++++++++++++++ lldptool.c | 2 + 6 files changed, 622 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.cMakefile.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.hinclude/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@@ -0,0 +1,44 @@ +/******************************************************************************* + +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_CMDS_H +#define _LLDP_VDP_CMDS_H + +struct arg_handlers *vdp_get_arg_handlers (); + +enum { +MODE =0 , +MGRID , +TYPEID , +TYPEIDVERSION , +INSTANCEID , +MAC , +VLAN , +}; + +#define VAL_STATION "station" +#define VAL_BRIDGE "bridge" + +#endif lldp_vdp_clif.c new file +42
-0@@ -0,0 +1,136 @@ +/******************************************************************************* + +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". + +*******************************************************************************/ + +#include "includes.h" +#include "common.h" +#include <stdio.h> +#include <syslog.h> +#include <sys/un.h> +#include <sys/stat.h> +#include "lldp_mod.h" +#include "lldptool.h" +#include "lldp.h" +#include "lldp_vdp.h" +#include "lldp_vdp_clif.h" + +void vdp_print_cfg_tlv (u16 ,char *info); +int vdp_print_help (); + +u32 vdp_lookup_tlv_name (char *tlvid_str); +snip
Quoted 11 lines
lldp_vdp_clif.c new file +11
-0+ +static int get_arg_mode (struct cmd *cmd,char *arg,char *argvalue, +char *obuf) +{ +char *s, *t; +struct vsi_profile *np; +struct vdp_data *vd; + +if (cmd->cmd != cmd_gettlv) +return cmd_invalid; +lldp_vdp_clif.c
Quoted 10 lines
lldp_vdp_clif.c new file +10
-0+switch (cmd->tlvid) { +case ((LLDP_MOD_VDP ) <<8 ) |LLDP_VDP_SUBTYPE : +break ; +case INVALID_TLVID : +return cmd_invalid; +default : +return cmd_not_applicable; + } + + s = t =malloc (VDP_BUF_SIZE );memory leak on s or maybe I missed something.
Quoted 16 lines
lldp_vdp_clif.c new file +16
-0+if (!s) +return cmd_invalid; +memset (s,0 ,VDP_BUF_SIZE ); + + vd =vdp_data (cmd->ifname); +if (!vd) { +printf ("%s(%i): vdp_data for %s not found !\n" , __func__, __LINE__, + cmd->ifname); +return cmd_invalid; + } + + LIST_FOREACH(np, &vd->profile_head, profile) { +PRINT_PROFILE (t, np); + } + + sprintf(obuf, "%02x%s%04x%s", (unsigned int) strlen(arg), arg,
Quoted 9 lines
lldp_vdp_clif.c
Quoted 5 lines
lldp_vdp_clif.c new file +5
-0+ (unsigned int) strlen(s), s); + +return cmd_success; +} +Thanks,
John.
Will be fixed in my next posting of the series.
Thanks !
Jens
Signature · 5 lines
IBM Deutschland Research & Development GmbH Vorsitzender des Aufsichtsrats: Martin Jetter Geschäftsführung: Dirk Wittkopp Sitz der Gesellschaft: Böblingen Registergericht: Amtsgericht Stuttgart, HRB 243294
PATCH 7/10 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 8/10 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 9/10 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 | 609 ++++++++++++++++++++++++++++++++++++++++++++++++- include/event_iface.h | 1 + include/lldp_vdp.h | 2 + lldp_vdp.c | 2 +- lldpad.c | 10 + 5 files changed, 617 insertions(+), 7 deletions(-)
event_iface.c +603 -6
@@ -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"
@@ -55,6 +66,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 +257,536 @@ 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 */ +fprintf (stderr,"%s:%s: nlmsg_type: %d\n" , __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; + +fprintf (stderr,"%s:%s:%d\n" , __FILE__, __FUNCTION__, __LINE__); + +if (nlmsg_parse (nlh,sizeof (struct ifinfomsg ), + (struct nlattr **)&tb,IFLA_MAX ,NULL )) { +fprintf (stderr,"Error parsing request...\n" ); +return -EINVAL ; + } + +if (tb[IFLA_IFNAME ]) { + ifname = (char *)RTA_DATA (tb[IFLA_IFNAME ]); +fprintf (stderr,"IFLA_IFNAME=%s\n" , ifname); + }else { + ifinfo = (struct ifinfomsg *)NLMSG_DATA (nlh); + *ifindex = ifinfo->ifi_index; +fprintf (stderr,"interface index: %d\n" , 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; + +fprintf (stderr,"%s:%s:%d\n" , __FILE__, __FUNCTION__, __LINE__); + + 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 )) { +fprintf (stderr,"Error parsing request...\n" ); +return -EINVAL ; + } + +fprintf (stderr,"%s(%d): nlmsg_len %i\n" , __FILE__, __LINE__, nlh->nlmsg_len); + +if (tb[IFLA_IFNAME ]) { + ifname = (char *)RTA_DATA (tb[IFLA_IFNAME ]); +fprintf (stderr,"IFLA_IFNAME=%s\n" , ifname); + }else { + ifinfo = (struct ifinfomsg *)NLMSG_DATA (nlh); +fprintf (stderr,"interface index: %d\n" , ifinfo->ifi_index); + } + +fprintf (stderr,"%s:%s:%d\n" , __FILE__, __FUNCTION__, __LINE__); + +if (!tb[IFLA_VFINFO_LIST ]) { +fprintf (stderr,"IFLA_VFINFO_LIST missing.\n" ); +return -EINVAL ; + }else { +fprintf (stderr,"FOUND IFLA_VFINFO_LIST!\n" ); + } + +nla_for_each_nested (tb_vfinfo_list, tb[IFLA_VFINFO_LIST ], rem) { +if (nla_type (tb_vfinfo_list) !=IFLA_VF_INFO ) { +fprintf (stderr,"nested parsing of IFLA_VFINFO_LIST failed.\n" ); +return -EINVAL ; + } + +if (nla_parse_nested (tb_vfinfo,IFLA_VF_MAX , tb_vfinfo_list, + ifla_vf_policy)) { +fprintf (stderr,"nested parsing of IFLA_VF_INFO failed.\n" ); +return -EINVAL ; + } + } + +if (tb_vfinfo[IFLA_VF_MAC ]) { +struct ifla_vf_mac *mac =RTA_DATA (tb_vfinfo[IFLA_VF_MAC ]); +u8 *m = mac->mac; +fprintf (stderr,"IFLA_VF_MAC=%2x:%2x:%2x:%2x:%2x:%2x\n" , + 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 ]); +fprintf (stderr,"IFLA_VF_VLAN=%d\n" , vlan->vlan); + profile->vlan = (u16 ) vlan->vlan; + } + +if (tb[IFLA_VF_PORTS ]) { +struct nlattr *tb_vf_ports; + +fprintf (stderr,"FOUND IFLA_VF_PORTS\n" ); + +nla_for_each_nested (tb_vf_ports, tb[IFLA_VF_PORTS ], rem) { + +fprintf (stderr,"ITERATING\n" ); + +if (nla_type (tb_vf_ports) !=IFLA_VF_PORT ) { +fprintf (stderr,"not a IFLA_VF_PORT. skipping\n" ); +continue ; + } + +if (nla_parse_nested (tb3,IFLA_PORT_MAX , tb_vf_ports, + ifla_port_policy)) { +fprintf (stderr,"nested parsing on level 2 failed.\n" ); +return -EINVAL ; + } + +fprintf (stderr,"%s:%s:%d\n" , __FILE__, __FUNCTION__, __LINE__); + +if (tb3[IFLA_PORT_VF ]) { +fprintf (stderr,"IFLA_PORT_VF=%d\n" , *(uint32_t *)(RTA_DATA (tb3[IFLA_PORT_VF ]))); + } + +if (tb3[IFLA_PORT_PROFILE ]) { +fprintf (stderr,"IFLA_PORT_PROFILE=%s\n" , (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 ]; +fprintf (stderr,"mgr_id : %d\n" +"type_id : %d\n" +"type_version : %d\n" , + pvsi->vsi_mgr_id, + tid, + 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 ]); +fprintf (stderr,"IFLA_PORT_INSTANCE_UUID=" ); + +for (i =0 ; i <16 ; i++) { +fprintf (stderr,"%x" ,uuid[i]); + } + +fprintf (stderr,"\n" ); + +memcpy (&profile->instance, +RTA_DATA (tb3[IFLA_PORT_INSTANCE_UUID ]),16 ); + } + +if (tb3[IFLA_PORT_REQUEST ]) { +fprintf (stderr,"IFLA_PORT_REQUEST=%d\n" , + *(uint8_t *)RTA_DATA (tb3[IFLA_PORT_REQUEST ])); + profile->mode = *(uint8_t *)RTA_DATA (tb3[IFLA_PORT_REQUEST ]); + } + +if (tb3[IFLA_PORT_RESPONSE ]) { +fprintf (stderr,"IFLA_PORT_RESPONSE=%d\n" , + *(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 { +printf ("%s(%i): Could not find port for %s\n" , __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 ]; + +fprintf (stderr,"%s:%s:%d\n" , __FILE__, __FUNCTION__, __LINE__); + +if (nlmsg_parse (nlh,sizeof (struct ifinfomsg ), + (struct nlattr **)&tb,IFLA_MAX ,NULL )) { +fprintf (stderr,"Error parsing response...\n" ); +return ; + } + +if (tb[IFLA_IFNAME ]) { +fprintf (stderr,"IFLA_IFNAME=%s\n" , (char *)RTA_DATA (tb[IFLA_IFNAME ])); + }else { +struct ifinfomsg *ifinfo = (struct ifinfomsg *)NLMSG_DATA (nlh); +fprintf (stderr,"interface index: %d\n" , 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)) { +fprintf (stderr,"nested parsing on level 1 failed.\n" ); +return ; + } + +if (tb2[IFLA_VF_PORT ]) { +if (nla_parse_nested (tb3,IFLA_PORT_MAX , tb2[IFLA_VF_PORT ], + ifla_port_policy)) { +fprintf (stderr,"nested parsing on level 2 failed.\n" ); +return ; + } + +if (tb3[IFLA_PORT_VF ]) { +fprintf (stderr,"IFLA_PORT_VF=%d\n" , *(uint32_t *)(RTA_DATA (tb3[IFLA_PORT_VF ]))); + } + +if (tb3[IFLA_PORT_PROFILE ]) { +fprintf (stderr,"IFLA_PORT_PROFILE=%s\n" , (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 ]; +fprintf (stderr,"mgr_id : %d\n" +"type_id : %d\n" +"type_version : %d\n" , + 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 ]); + +fprintf (stderr,"IFLA_PORT_INSTANCE_UUID=" ); + +for (i =0 ; i <16 ; i++) { +fprintf (stderr,"%x" ,uuid[i]); + } + +fprintf (stderr,"\n" ); + } + +if (tb3[IFLA_PORT_REQUEST ]) { +fprintf (stderr,"IFLA_PORT_REQUEST=%d\n" , + *(uint8_t *)RTA_DATA (tb3[IFLA_PORT_REQUEST ])); + } + +if (tb3[IFLA_PORT_RESPONSE ]) { +fprintf (stderr,"IFLA_PORT_RESPONSE=%d\n" , + *(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; + +fprintf (stderr,"%s:%s:%d\n" , __FILE__, __FUNCTION__, __LINE__); + + nl_msg =nlmsg_alloc (); + +if (!nl_msg) { +printf ("%s(%i): Unable to allocate netlink message !\n" , __func__, __LINE__); +return NULL ; + } + +if (!if_indextoname (ifindex, ifname)) { +printf ("%s(%i): No name found for interface with index %i !\n" , __func__, __LINE__, + ifindex); + } + + vd =vdp_data (ifname); +if (!vd) { +printf ("%s(%i): Could not find vdp_data for %s !\n" , __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; +fprintf (stderr,"RESPONSE ERROR CODE: %d\n" ,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) { +printf ("%s(%i): could not allocate nlh !\n" , __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 ; + +fprintf (stderr,"Waiting for message \n" ); + result =recvmsg (sock, &msg,MSG_DONTWAIT ); + +fprintf (stderr,"%s:%s: recvmsg received %d bytes\n" , __FILE__, __FUNCTION__, result); + +if (result <0 ) { +fprintf (stderr,"Error receiving from netlink socket : %s\n" ,strerror (errno)); + } + +fprintf (stderr,"%s:%s: dest_addr.nl_pid: %d\n" , __FILE__, __FUNCTION__, dest_addr.nl_pid); +fprintf (stderr,"%s:%s: nlh.nl_pid: %d\n" , __FILE__, __FUNCTION__, nlh->nlmsg_pid); +fprintf (stderr,"%s:%s: nlh_type: %d\n" , __FILE__, __FUNCTION__, nlh->nlmsg_type); +fprintf (stderr,"%s:%s: nlh_seq: 0x%x\n" , __FILE__, __FUNCTION__, nlh->nlmsg_seq); +fprintf (stderr,"%s:%s: nlh_len: 0x%x\n" , __FILE__, __FUNCTION__, nlh->nlmsg_len); + +switch (nlh->nlmsg_type) { +case RTM_SETLINK : +fprintf (stderr,"--> RTM_SETLINK\n" ); + + 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 : +fprintf (stderr,"--> RTM_GETLINK\n" ); + + 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); +printf ("%s(%i): ifname %s (%d)\n" , __func__, + __LINE__, ifname, ifindex); + }else { + ifname =malloc (IFNAMSIZ ); +printf ("%s(%i): ifindex %i\n" , __func__, + __LINE__, ifindex); + } + + nl_msg =event_if_constructResponse (nlh, ifindex); + +if (!nl_msg) { +printf ("%s(%i): Unable to construct response !\n" , + __func__, __LINE__); + goto out_err; + } + + nlh =nlmsg_hdr (nl_msg); + +fprintf (stderr,"------------\nRESPONSE:\n" ); + +event_if_parseResponseMsg (nlh); + +fprintf (stderr,"------------\n" ); +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 ) { +fprintf (stderr,"Error sending on netlink socket : %s\n" ,strerror (errno)); + }else { +fprintf (stderr,"sent %d bytes!\n" ,result); + } + +out_err: +free (nlh); +} +static void event_iface_receive (int sock,void *eloop_ctx,void *sock_ctx) {struct nlmsghdr *nlh;
@@ -236,10 +794,11 @@ 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); +fprintf (stderr,"%s:%s: result: %d\n" , __FILE__, __FUNCTION__, result);if (result <0 ) {perror ("recvfrom(Event interface)" );if ((errno ==ENOBUFS ) || (errno ==EAGAIN ))
@@ -250,10 +809,14 @@ 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*/ +fprintf (stderr,"%s:%s: dest_addr.nl_pid: %d\n" , __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 ()
@@ -262,6 +825,7 @@ int event_iface_init()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 +846,39 @@ int event_iface_init() }eloop_register_read_sock (fd, event_iface_receive,NULL ,NULL ); +// event_iface_init2(); +return 0 ; +} + +int event_iface_init_user_space () +{ +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 ) +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); +fprintf (stderr,"Error binding to netlink socket : %s\n" ,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) {char *s, *t;
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 10/10 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 | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 89 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 +86 -0
110 lines not on this page · raw message
Signature · 1 line
1.7.1