From 91eb6d5df80933d089bda9543b2dbf3d97d462e1 Mon Sep 17 00:00:00 2001 From: Vincent Bernat Date: Sun, 25 Apr 2010 12:26:17 +0200 Subject: [PATCH] Blacklist VMWare interfaces (as per ticket #40). --- CHANGELOG | 4 ++-- src/interfaces.c | 30 ++++++++++++++++++++++++++++++ src/lldpd.c | 1 + src/lldpd.h | 1 + 4 files changed, 34 insertions(+), 2 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 702579fa..9a120a59 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -10,8 +10,8 @@ lldpd (0.5.1) + Add a new output (keyvalue) for lldpctl. * Fixes: - + Ignore interface with no queue. It should filter out interfaces - like "vnet0" that would fail if we try to send something on them. + + Ignore interface with no queue. + + Ignore VMWare interfaces. lldpd (0.5.0) diff --git a/src/interfaces.c b/src/interfaces.c index 5dbf3671..5d01c9a7 100644 --- a/src/interfaces.c +++ b/src/interfaces.c @@ -34,6 +34,7 @@ #include #include #include +#include #define SYSFS_PATH_MAX 256 #define MAX_PORTS 1024 @@ -617,6 +618,35 @@ iface_fds_close(struct lldpd *cfg, struct lldpd_hardware *hardware) } } +void +lldpd_ifh_blacklist(struct lldpd *cfg, struct ifaddrs *ifap) +{ + struct ifaddrs *ifa; + const char* blacklisted[] = { + "vnet[0-9][0-9]*", + NULL + }; + const char **f; + regex_t preg; + + for (ifa = ifap; ifa != NULL; ifa = ifa->ifa_next) { + if (!ifa->ifa_flags) + continue; + + for (f=blacklisted; *f != NULL; f++) { + if (regcomp(&preg, *f, REG_NOSUB) != 0) + /* Should not happen */ + fatal("unable to compile a regex"); + if (regexec(&preg, ifa->ifa_name, 0, NULL, 0) == 0) { + regfree(&preg); + break; + } + regfree(&preg); + } + if (*f != NULL) + ifa->ifa_flags = 0; /* Blacklisted */ + } +} static int iface_eth_init(struct lldpd *cfg, struct lldpd_hardware *hardware) diff --git a/src/lldpd.c b/src/lldpd.c index f2a97d1a..09ac0809 100644 --- a/src/lldpd.c +++ b/src/lldpd.c @@ -745,6 +745,7 @@ lldpd_update_localports(struct lldpd *cfg) struct ifaddrs *ifap; struct lldpd_hardware *hardware; lldpd_ifhandlers ifhs[] = { + lldpd_ifh_blacklist, /* Do not handle those interfaces */ lldpd_ifh_bond, /* Handle bond */ lldpd_ifh_eth, /* Handle classic ethernet interfaces */ #ifdef ENABLE_DOT1 diff --git a/src/lldpd.h b/src/lldpd.h index 7bead796..376ef043 100644 --- a/src/lldpd.h +++ b/src/lldpd.h @@ -404,6 +404,7 @@ int ctl_msg_pack_structure(char *, void *, unsigned int, struct hmsg *, void ** int ctl_msg_unpack_structure(char *, void *, unsigned int, struct hmsg *, void **); /* interfaces.c */ +void lldpd_ifh_blacklist(struct lldpd *, struct ifaddrs *); void lldpd_ifh_bond(struct lldpd *, struct ifaddrs *); void lldpd_ifh_eth(struct lldpd *, struct ifaddrs *); #ifdef ENABLE_DOT1 -- 2.39.5