/* Fetch interface information via ioctl(). */ static void interface_info_ioctl (struct interface *ifp) { if_get_index (ifp); if_get_flags (ifp); if_get_mtu (ifp); if_get_metric (ifp); }
static int use_if_ether(struct cli_context *ctx, char *name, int index, int switchport) { int status, sock_fd, ioctl_errno; struct swcli_context *uc = SWCLI_CTX(ctx); struct cdp_session *cdp; FILE *out; SW_SOCK_OPEN(ctx, sock_fd); if (!index) index = if_get_index(name, sock_fd); if (!index) { EX_STATUS_REASON(ctx, "interface %s does not exist", name); SW_SOCK_CLOSE(ctx, sock_fd); return CLI_EX_REJECTED; } status = sw_ops->if_add(sw_ops, index, switchport); ioctl_errno = errno; if (status) { switch (ioctl_errno) { case ENODEV: EX_STATUS_REASON(ctx, "interface %s does not exist", name); return CLI_EX_REJECTED; case EINVAL: EX_STATUS_REASON(ctx, "interface %s is a VIF", name); return CLI_EX_REJECTED; case EBUSY: break; default: EX_STATUS_REASON_IOCTL(ctx, ioctl_errno); return CLI_EX_REJECTED; } } else { /* Try to enable CDP on this interface */ do { if (!CDP_SESSION_OPEN(ctx, cdp)) { out = ctx->out_open(ctx, 0); fprintf(out, "WARNING: failed to enable cdp on interface %s : %s\n", name, strerror(errno)); break; } cdp_set_interface(cdp, index, 1); CDP_SESSION_CLOSE(ctx, cdp); } while (0); } ctx->node_filter &= PRIV_FILTER(PRIV_MAX); ctx->node_filter |= IFF_SWITCHED; ctx->root = &config_if_main; uc->ifindex = index; uc->vlan = -1; return CLI_EX_OK; }
/* Fetch interface information via ioctl(). */ static void interface_info_ioctl() { struct listnode *node, *nnode; struct interface *ifp; for (ALL_LIST_ELEMENTS(iflist, node, nnode, ifp)) { if_get_index(ifp); #ifdef SIOCGIFHWADDR if_get_hwaddr(ifp); #endif /* SIOCGIFHWADDR */ if_get_flags(ifp); #ifndef HAVE_GETIFADDRS if_get_addr(ifp); #endif /* ! HAVE_GETIFADDRS */ if_get_mtu(ifp); if_get_metric(ifp); } }
/* Open "interface", and add packetio_recv_handler(state) as the IO * event handler for its packets (or die on failure). If possible, * the OSL should try to set the OS to filter packets so just frames * with ethertype == topology protocol are received, but if not the * packetio_recv_handler will filter appropriately, so providing more * frames than necessary is safe. */ void osl_interface_open(osl_t *osl, char *interface, void *state) { struct sockaddr_ll addr; int ret; osl->sock = socket(PF_PACKET, SOCK_RAW, TOPO_ETHERTYPE); if (osl->sock < 0) die("osl_interface_open: open %s failed: %s\n", interface, strerror(errno)); osl->interface = interface; /* perhaps check interface flags indicate it is up? */ /* set filter to only topology frames on this one interface */ memset(&addr, 0, sizeof(addr)); addr.sll_family = AF_PACKET; addr.sll_protocol = TOPO_ETHERTYPE; addr.sll_ifindex = if_get_index(osl->sock, interface); DEBUG({printf("binding raw socket (index= %d, fd=%d) on %s to TOPO_ETHERTYPE\n", addr.sll_ifindex, osl->sock, osl->interface);})
/* Fetch interface information via ioctl(). */ static void interface_info_ioctl () { struct listnode *node; struct interface_FOO *ifp; LIST_LOOP (iflist, ifp, node) { ifp = getdata (node); if_get_index (ifp); #ifdef SIOCGIFHWADDR if_get_hwaddr (ifp); #endif /* SIOCGIFHWADDR */ if_get_flags (ifp); #ifndef HAVE_GETIFADDRS if_get_addr (ifp); #endif /* ! HAVE_GETIFADDRS */ if_get_mtu (ifp); if_get_metric (ifp); }
/* Fetch interface information via ioctl(). */ static void interface_info_ioctl () { listnode node; struct interface *ifp; for (node = listhead (iflist); node; node = nextnode (node)) { ifp = getdata (node); if_get_index (ifp); #ifdef SIOCGIFHWADDR if_get_hwaddr (ifp); #endif /* SIOCGIFHWADDR */ if_get_flags (ifp); #ifndef HAVE_GETIFADDRS if_get_addr (ifp); #endif /* ! HAVE_GETIFADDRS */ if_get_mtu (ifp); if_get_metric (ifp); } }
static int remove_if_ether(struct cli_context *ctx, char *name, int index, int switchport) { int sock_fd; int status; struct cdp_session *cdp; FILE *out; SW_SOCK_OPEN(ctx, sock_fd); if (!index) index = if_get_index(name, sock_fd); if (!index) { SW_SOCK_CLOSE(ctx, sock_fd); return CLI_EX_OK; } /* Try to disable CDP on this interface */ do { if (!CDP_SESSION_OPEN(ctx, cdp)) { out = ctx->out_open(ctx, 0); fprintf(out, "WARNING: failed to disable cdp on interface %s: %s\n", name, strerror(errno)); break; } cdp_set_interface(cdp, index, 0); CDP_SESSION_CLOSE(ctx, cdp); } while (0); SW_SOCK_CLOSE(ctx, sock_fd); status = sw_ops->if_remove(sw_ops, index); if (status) { EX_STATUS_REASON(ctx, "if_remove failed"); return CLI_EX_REJECTED; } return CLI_EX_OK; }