From 71936c67e6d49a400b1b87a953c6c348bcf55dee Mon Sep 17 00:00:00 2001 From: Vincent Bernat Date: Thu, 14 May 2009 16:08:05 +0200 Subject: [PATCH] Suppress "listen on vlan" feature. This will be reimplemented later in a more generic way. --- man/lldpd.8 | 8 +-- src/lldpd.c | 165 +--------------------------------------------------- src/lldpd.h | 17 ------ 3 files changed, 3 insertions(+), 187 deletions(-) diff --git a/man/lldpd.8 b/man/lldpd.8 index ea31ac42..6f000737 100644 --- a/man/lldpd.8 +++ b/man/lldpd.8 @@ -21,7 +21,7 @@ .Nd LLDP daemon .Sh SYNOPSIS .Nm -.Op Fl dvxcsei +.Op Fl dxcsei .Op Fl m Ar management .Op Fl p Ar probe time .Op Fl M Ar class @@ -55,12 +55,6 @@ If this option is specified, will run in the foreground and log to .Em stderr . This option can be specified many times to increase verbosity. -.It Fl v -Listen on VLAN as well. This option might be needed if your equipment -send frames on VLAN instead of physical interface. This option enables -.Nm -to receive frames on VLAN interfaces as well. If you don't need this -option, do not set it. .It Fl x Enable SNMP subagent With this option, diff --git a/src/lldpd.c b/src/lldpd.c index 358dc828..39c67e7b 100644 --- a/src/lldpd.c +++ b/src/lldpd.c @@ -49,7 +49,6 @@ static void usage(void); static int lldpd_iface_init(struct lldpd *, struct lldpd_hardware *); -static int lldpd_iface_init_vlan(struct lldpd *, struct lldpd_vif *); static void lldpd_iface_init_mtu(struct lldpd *, struct lldpd_hardware *); static int lldpd_iface_close(struct lldpd *, struct lldpd_hardware *); static void lldpd_iface_multicast(struct lldpd *, const char *, int); @@ -199,35 +198,6 @@ lldpd_iface_init_mtu(struct lldpd *global, struct lldpd_hardware *hardware) hardware->h_mtu = hardware->h_lport.p_mfs = ifr.ifr_mtu; } -static int -lldpd_iface_init_vlan(struct lldpd *global, struct lldpd_vif *vif) -{ - int status; - short int filter; - - lldpd_iface_init_mtu(global, (struct lldpd_hardware*)vif); - status = priv_iface_init((struct lldpd_hardware*)vif, -1); - if (status != 0) - return status; - - if (global->g_multi) - filter = LLDPD_MODE_ANY; - else - filter = LLDPD_MODE_LLDP; - - if (lldpd_iface_switchto(global, filter, - (struct lldpd_hardware*)vif) == -1) { - LLOG_WARNX("unable to apply filter"); - return ENETDOWN; - } - - lldpd_iface_multicast(global, vif->vif_ifname, 0); - - LLOG_DEBUG("vlan interface %s initialized (fd=%d)", vif->vif_ifname, - vif->vif_raw); - return 0; -} - static int lldpd_iface_init(struct lldpd *global, struct lldpd_hardware *hardware) { @@ -439,7 +409,6 @@ void lldpd_cleanup(struct lldpd *cfg) { struct lldpd_hardware *hardware, *hardware_next; - struct lldpd_vif *vif, *vif_next; for (hardware = TAILQ_FIRST(&cfg->g_hardware); hardware != NULL; hardware = hardware_next) { @@ -457,69 +426,6 @@ lldpd_cleanup(struct lldpd *cfg) } } } - for (vif = TAILQ_FIRST(&cfg->g_vif); vif != NULL; - vif = vif_next) { - vif_next = TAILQ_NEXT(vif, vif_entries); - if (vif->vif_flags == 0) { - TAILQ_REMOVE(&cfg->g_vif, vif, vif_entries); - lldpd_iface_close(cfg, (struct lldpd_hardware*)vif); - free(vif); - } - } -} - -static struct lldpd_vif * -lldpd_port_add_vlan(struct lldpd *cfg, struct ifaddrs *ifa) -{ - struct lldpd_vif *vif; - struct lldpd_hardware *hardware; - struct vlan_ioctl_args ifv; - - TAILQ_FOREACH(vif, &cfg->g_vif, vif_entries) { - if (strcmp(vif->vif_ifname, ifa->ifa_name) == 0) - break; - } - - if (vif == NULL) { - if ((vif = (struct lldpd_vif *) - calloc(1, sizeof(struct lldpd_vif))) == NULL) - return NULL; - vif->vif_raw = -1; - vif->vif_raw_real = -1; - } - strlcpy(vif->vif_ifname, ifa->ifa_name, sizeof(vif->vif_ifname)); - vif->vif_flags = ifa->ifa_flags; - - if (vif->vif_raw == -1) { - - if (lldpd_iface_init_vlan(cfg, vif) != 0) { - free(vif); - return NULL; - } - - /* Find the real interface */ - vif->vif_real = NULL; - TAILQ_FOREACH(hardware, &cfg->g_hardware, h_entries) { - memset(&ifv, 0, sizeof(ifv)); - ifv.cmd = GET_VLAN_REALDEV_NAME_CMD; - strlcpy(ifv.device1, ifa->ifa_name, sizeof(ifv.device1)); - if ((ioctl(cfg->g_sock, SIOCGIFVLAN, &ifv) >= 0) && - (strncmp(hardware->h_ifname, - ifv.u.device2, - sizeof(ifv.u.device2)) == 0)) - vif->vif_real = hardware; - } - if (vif->vif_real == NULL) { - LLOG_WARNX("unable to find real interface for %s", - ifa->ifa_name); - free(vif); - return NULL; - } - - TAILQ_INSERT_TAIL(&cfg->g_vif, vif, vif_entries); - } - - return vif; } static struct lldpd_hardware * @@ -991,7 +897,6 @@ static void lldpd_recv_all(struct lldpd *cfg) { struct lldpd_hardware *hardware; - struct lldpd_vif *vif; struct lldpd_client *client, *client_next; fd_set rfds; struct timeval tv; @@ -1032,14 +937,6 @@ lldpd_recv_all(struct lldpd *cfg) nfds = hardware->h_raw_real; } } - TAILQ_FOREACH(vif, &cfg->g_vif, vif_entries) { - if (((vif->vif_flags & IFF_UP) == 0) || - ((vif->vif_flags & IFF_RUNNING) == 0)) - continue; - FD_SET(vif->vif_raw, &rfds); - if (nfds < vif->vif_raw) - nfds = vif->vif_raw; - } TAILQ_FOREACH(client, &cfg->g_clients, next) { FD_SET(client->fd, &rfds); if (nfds < client->fd) @@ -1073,40 +970,6 @@ lldpd_recv_all(struct lldpd *cfg) snmp_timeout(); } #endif /* USE_SNMP */ - TAILQ_FOREACH(vif, &cfg->g_vif, vif_entries) { - if (!FD_ISSET(vif->vif_raw, &rfds)) - continue; - if ((buffer = (char *)malloc( - vif->vif_mtu)) == NULL) { - LLOG_WARN("failed to alloc reception buffer"); - continue; - } - fromlen = sizeof(from); - if ((n = recvfrom(vif->vif_raw, - buffer, - vif->vif_mtu, 0, - (struct sockaddr *)&from, - &fromlen)) == -1) { - LLOG_WARN("error while receiving frame on vlan %s", - vif->vif_ifname); - vif->vif_real->h_rx_discarded_cnt++; - free(buffer); - continue; - } - if (from.sll_pkttype == PACKET_OUTGOING) { - free(buffer); - continue; - } - if (!((cfg->g_multi) && - (vif->vif_real->h_mode != LLDPD_MODE_ANY) && - (lldpd_guess_type(cfg, buffer, n) != - vif->vif_real->h_mode))) { - vif->vif_real->h_rx_cnt++; - lldpd_decode(cfg, buffer, n, vif->vif_real, 0); - } - - free(buffer); - } TAILQ_FOREACH(hardware, &cfg->g_hardware, h_entries) { /* We could have received something on _real_ * interface. However, even in this case, this could be @@ -1260,7 +1123,6 @@ lldpd_loop(struct lldpd *cfg) struct ifaddrs *ifap, *ifa; struct sockaddr_ll *sdl; struct lldpd_hardware *hardware; - struct lldpd_vif *vif; int f; char status; struct utsname *un; @@ -1300,8 +1162,6 @@ lldpd_loop(struct lldpd *cfg) TAILQ_FOREACH(hardware, &cfg->g_hardware, h_entries) hardware->h_flags = 0; - TAILQ_FOREACH(vif, &cfg->g_vif, vif_entries) - vif->vif_flags = 0; if (getifaddrs(&ifap) != 0) fatal("lldpd_loop: failed to get interface list"); @@ -1363,17 +1223,6 @@ lldpd_loop(struct lldpd *cfg) ifa->ifa_name); } - /* Handle VLAN */ - if (cfg->g_listen_vlans) { - for (ifa = ifap; ifa != NULL; ifa = ifa->ifa_next) { - if ((iface_is_vlan(cfg, ifa->ifa_name)) && - (lldpd_port_add_vlan(cfg, ifa) == NULL)) { - LLOG_WARNX("unable to allocate vlan %s, skip it", - ifa->ifa_name); - } - } - } - freeifaddrs(ifap); lldpd_cleanup(cfg); @@ -1396,17 +1245,12 @@ static void lldpd_exit() { struct lldpd_hardware *hardware; - struct lldpd_vif *vif; close(gcfg->g_ctl); priv_ctl_cleanup(); TAILQ_FOREACH(hardware, &gcfg->g_hardware, h_entries) { if (INTERFACE_OPENED(hardware)) lldpd_iface_close(gcfg, hardware); } - TAILQ_FOREACH(vif, &gcfg->g_vif, vif_entries) { - if (vif->vif_raw != -1) - lldpd_iface_close(gcfg, (struct lldpd_hardware*)vif); - } #ifdef USE_SNMP if (gcfg->g_snmp) agent_shutdown(); @@ -1422,8 +1266,8 @@ main(int argc, char *argv[]) int snmp = 0; #endif char *mgmtp = NULL; - char *popt, opts[] = "vdxm:p:M:i@ "; - int probe = 0, i, found, vlan = 0; + char *popt, opts[] = "dxm:p:M:i@ "; + int probe = 0, i, found; #ifdef ENABLE_LLDPMED int lldpmed = 0, noinventory = 0; #endif @@ -1441,9 +1285,6 @@ main(int argc, char *argv[]) *popt = '\0'; while ((ch = getopt(argc, argv, opts)) != -1) { switch (ch) { - case 'v': - vlan = 1; - break; case 'd': debug++; break; @@ -1521,7 +1362,6 @@ main(int argc, char *argv[]) fatal(NULL); cfg->g_mgmt_pattern = mgmtp; - cfg->g_listen_vlans = vlan; /* Get ioctl socket */ if ((cfg->g_sock = socket(AF_INET, SOCK_DGRAM, 0)) == -1) @@ -1557,7 +1397,6 @@ main(int argc, char *argv[]) cfg->g_multi--; TAILQ_INIT(&cfg->g_hardware); - TAILQ_INIT(&cfg->g_vif); #ifdef USE_SNMP if (snmp) { diff --git a/src/lldpd.h b/src/lldpd.h index 29532423..0fc5c265 100644 --- a/src/lldpd.h +++ b/src/lldpd.h @@ -228,21 +228,6 @@ struct lldpd_hardware { struct lldpd_chassis *h_rchassis; }; -/* lldpd_vif can be casted to lldpd_hardware on some cases */ -struct lldpd_vif { - TAILQ_ENTRY(lldpd_vif) vif_entries; - int vif_raw; - int vif_raw_real; /* Not used */ - int vif_master; /* Not used */ - int vif_mode; /* Not used */ - int vif_flags; - int vif_mtu; - char vif_ifname[IFNAMSIZ]; - - /* No more compatibility with struct lldpd_hardware from here */ - struct lldpd_hardware *vif_real; -}; - struct lldpd_interface { TAILQ_ENTRY(lldpd_interface) next; char *name; @@ -279,7 +264,6 @@ struct lldpd { struct protocol *g_protocols; int g_multi; /* Set to 1 if multiple protocols */ int g_probe_time; - int g_listen_vlans; #ifdef ENABLE_LLDPMED int g_noinventory; #endif @@ -299,7 +283,6 @@ struct lldpd { struct lldpd_chassis g_lchassis; TAILQ_HEAD(, lldpd_hardware) g_hardware; - TAILQ_HEAD(, lldpd_vif) g_vif; }; enum hmsg_type { -- 2.39.5