/* Set interface flags */ int if_set_flags(struct interface *ifp, uint64_t flags) { int ret; struct lifreq lifreq; lifreq_set_name(&lifreq, ifp->name); lifreq.lifr_flags = ifp->flags; lifreq.lifr_flags |= flags; if (ifp->flags & IFF_IPV4) ret = AF_IOCTL(AF_INET, SIOCSLIFFLAGS, (caddr_t)&lifreq); else if (ifp->flags & IFF_IPV6) ret = AF_IOCTL(AF_INET6, SIOCSLIFFLAGS, (caddr_t)&lifreq); else ret = -1; if (ret < 0) zlog_info("can't set interface flags on %s: %s", ifp->name, safe_strerror(errno)); else ret = 0; return ret; }
/* * get interface metric * -- if value is not avaliable set -1 */ void if_get_metric (struct interface *ifp) { struct lifreq lifreq; int ret; lifreq_set_name (&lifreq, ifp->name); if (ifp->flags & IFF_IPV4) ret = AF_IOCTL (AF_INET, SIOCGLIFMETRIC, (caddr_t) & lifreq); #ifdef SOLARIS_IPV6 else if (ifp->flags & IFF_IPV6) ret = AF_IOCTL (AF_INET6, SIOCGLIFMETRIC, (caddr_t) & lifreq); #endif /* SOLARIS_IPV6 */ else ret = -1; if (ret < 0) return; ifp->metric = lifreq.lifr_metric; if (ifp->metric == 0) ifp->metric = 1; }
/* Get interface's index by ioctl. */ static int if_get_index (struct interface *ifp) { int ret; struct lifreq lifreq; lifreq_set_name (&lifreq, ifp->name); if (ifp->flags & IFF_IPV4) ret = AF_IOCTL (AF_INET, SIOCGLIFINDEX, (caddr_t) & lifreq); else if (ifp->flags & IFF_IPV6) ret = AF_IOCTL (AF_INET6, SIOCGLIFINDEX, (caddr_t) & lifreq); else ret = -1; if (ret < 0) { zlog_warn ("SIOCGLIFINDEX(%s) failed", ifp->name); return ret; } /* OK we got interface index. */ #ifdef ifr_ifindex ifp->ifindex = lifreq.lifr_ifindex; #else ifp->ifindex = lifreq.lifr_index; #endif return ifp->ifindex; }
/* Unset interface's flag. */ int if_unset_flags (struct interface_FOO *ifp, uint64_t flags) { int ret; struct lifreq lifreq; lifreq_set_name (&lifreq, ifp->name); lifreq.lifr_flags = ifp->flags; lifreq.lifr_flags &= ~flags; if (ifp->flags & IFF_IPV4) ret = AF_IOCTL (AF_INET, SIOCSLIFFLAGS, (caddr_t) & lifreq); else if (ifp->flags & IFF_IPV6) ret = AF_IOCTL (AF_INET6, SIOCSLIFFLAGS, (caddr_t) & lifreq); else ret = -1; if (ret < 0) zlog_info ("can't unset interface flags"); else ret = 0; return ret; }
/* get interface MTU */ void if_get_mtu (struct interface *ifp) { struct lifreq lifreq; int ret; u_char changed = 0; if (ifp->flags & IFF_IPV4) { lifreq_set_name (&lifreq, ifp->name); ret = AF_IOCTL (AF_INET, SIOCGLIFMTU, (caddr_t) & lifreq); if (ret < 0) { zlog_info ("Can't lookup mtu on %s by ioctl(SIOCGLIFMTU)", ifp->name); ifp->mtu = -1; } else { ifp->mtu = lifreq.lifr_metric; changed = 1; } } #ifdef HAVE_IPV6 if (ifp->flags & IFF_IPV6) { memset(&lifreq, 0, sizeof(lifreq)); lifreq_set_name (&lifreq, ifp->name); ret = AF_IOCTL (AF_INET6, SIOCGLIFMTU, (caddr_t) & lifreq); if (ret < 0) { zlog_info ("Can't lookup mtu6 on %s by ioctl(SIOCGIFMTU)", ifp->name); ifp->mtu6 = -1; } else { ifp->mtu6 = lifreq.lifr_metric; changed = 1; } } #endif /* HAVE_IPV6 */ if (changed) zebra_interface_up_update(ifp); }
/* Get just the flags for the given name. * Used by the normal 'if_get_flags' function, as well * as the bootup interface-list code, which has to peek at per-address * flags in order to figure out which ones should be ignored.. */ int if_get_flags_direct(const char *ifname, uint64_t *flags, unsigned int af) { struct lifreq lifreq; int ret; lifreq_set_name(&lifreq, ifname); ret = AF_IOCTL(af, SIOCGLIFFLAGS, (caddr_t)&lifreq); if (ret) zlog_debug("%s: ifname %s, error %s (%d)", __func__, ifname, safe_strerror(errno), errno); *flags = lifreq.lifr_flags; return ret; }