stream_get(ifname_tmp, s, INTERFACE_NAMSIZ);
/* And look it up. */
- return if_lookup_by_name_len(
- ifname_tmp, strnlen(ifname_tmp, INTERFACE_NAMSIZ), VRF_DEFAULT);
+ return if_lookup_by_name(ifname_tmp, VRF_DEFAULT);
}
void eigrp_zebra_route_add(struct prefix *p, struct list *successors)
}
/* Create new interface structure. */
-struct interface *if_create(const char *name, int namelen, vrf_id_t vrf_id)
+struct interface *if_create(const char *name, vrf_id_t vrf_id)
{
struct interface *ifp;
struct list *intf_list = vrf_iflist_get(vrf_id);
ifp->ifindex = IFINDEX_INTERNAL;
assert(name);
- assert(namelen <= INTERFACE_NAMSIZ); /* Need space for '\0' at end. */
- strncpy(ifp->name, name, namelen);
- ifp->name[namelen] = '\0';
+ strlcpy(ifp->name, name, sizeof(ifp->name));
ifp->vrf_id = vrf_id;
if (if_lookup_by_name(ifp->name, vrf_id) == NULL)
listnode_add_sort(intf_list, ifp);
listnode_add_sort(intf_list, ifp);
else
zlog_err(
- "if_create(%s): corruption detected -- interface with this "
- "name exists already in VRF %u!",
+ "%s(%s): corruption detected -- interface with this "
+ "name exists already in VRF %u!", __func__,
ifp->name, vrf_id);
return;
struct listnode *node;
struct interface *ifp;
- if (name)
- for (ALL_LIST_ELEMENTS_RO(vrf_iflist(vrf_id), node, ifp)) {
- if (strcmp(name, ifp->name) == 0)
- return ifp;
- }
- return NULL;
-}
-
-struct interface *if_lookup_by_name_all_vrf(const char *name)
-{
- struct vrf *vrf;
- struct interface *ifp;
+ if (!name || strnlen(name, INTERFACE_NAMSIZ) == INTERFACE_NAMSIZ)
+ return NULL;
- RB_FOREACH (vrf, vrf_id_head, &vrfs_by_id) {
- ifp = if_lookup_by_name(name, vrf->vrf_id);
- if (ifp)
+ for (ALL_LIST_ELEMENTS_RO(vrf_iflist(vrf_id), node, ifp)) {
+ if (strcmp(name, ifp->name) == 0)
return ifp;
}
return NULL;
}
-struct interface *if_lookup_by_name_len(const char *name, size_t namelen,
- vrf_id_t vrf_id)
+struct interface *if_lookup_by_name_all_vrf(const char *name)
{
- struct listnode *node;
+ struct vrf *vrf;
struct interface *ifp;
- if (namelen > INTERFACE_NAMSIZ)
+ if (!name || strnlen(name, INTERFACE_NAMSIZ) == INTERFACE_NAMSIZ)
return NULL;
- for (ALL_LIST_ELEMENTS_RO(vrf_iflist(vrf_id), node, ifp)) {
- if (!memcmp(name, ifp->name, namelen)
- && (ifp->name[namelen] == '\0'))
+ RB_FOREACH (vrf, vrf_id_head, &vrfs_by_id) {
+ ifp = if_lookup_by_name(name, vrf->vrf_id);
+ if (ifp)
return ifp;
}
+
return NULL;
}
/* Get interface by name if given name interface doesn't exist create
one. */
-struct interface *if_get_by_name(const char *name, vrf_id_t vrf_id)
+struct interface *if_get_by_name(const char *name, vrf_id_t vrf_id, int vty)
{
struct interface *ifp;
- return ((ifp = if_lookup_by_name(name, vrf_id)) != NULL)
- ? ifp
- : if_create(name, strlen(name), vrf_id);
-}
-
-struct interface *if_get_by_name_len(const char *name, size_t namelen,
- vrf_id_t vrf_id, int vty)
-{
- struct interface *ifp;
- struct vrf *vrf;
- struct listnode *node;
-
- ifp = if_lookup_by_name_len(name, namelen, vrf_id);
- if (ifp)
- return ifp;
+ ifp = if_lookup_by_name_all_vrf(name);
+ if (ifp) {
+ if (ifp->vrf_id == vrf_id)
+ return ifp;
- /* Didn't find the interface on that vrf. Defined on a different one? */
- RB_FOREACH (vrf, vrf_id_head, &vrfs_by_id) {
- for (ALL_LIST_ELEMENTS_RO(vrf_iflist(vrf->vrf_id), node, ifp)) {
- if (!memcmp(name, ifp->name, namelen)
- && (ifp->name[namelen] == '\0')) {
- /* Found a match. If the interface command was
- * entered in vty without a
- * VRF (passed as VRF_DEFAULT), accept the ifp
- * we found. If a vrf was
- * entered and there is a mismatch, reject it if
- * from vty. If it came
- * from the kernel by way of zclient, believe
- * it and update
- * the ifp accordingly.
- */
- if (vty) {
- if (vrf_id == VRF_DEFAULT)
- return ifp;
- return NULL;
- } else {
- if_update_to_new_vrf(ifp, vrf_id);
- return ifp;
- }
- }
+ /* Found a match on a different VRF. If the interface command
+ * was entered in vty without a VRF (passed as VRF_DEFAULT),
+ * accept the ifp we found. If a vrf was entered and there is
+ * a mismatch, reject it if from vty. If it came from the kernel
+ * or by way of zclient, believe it and update the ifp
+ * accordingly.
+ */
+ if (vty) {
+ if (vrf_id == VRF_DEFAULT)
+ return ifp;
+ return NULL;
+ } else {
+ if_update_to_new_vrf(ifp, vrf_id);
+ return ifp;
}
}
- return (if_create(name, namelen, vrf_id));
+
+ return if_create(name, vrf_id);
}
/* Does interface up ? */
* if not:
* - no idea, just get the name in its entirety.
*/
-static struct interface *if_sunwzebra_get(const char *name, size_t nlen,
- vrf_id_t vrf_id)
+static struct interface *if_sunwzebra_get(char *name, vrf_id_t vrf_id)
{
struct interface *ifp;
- size_t seppos = 0;
+ char *cp;
- if ((ifp = if_lookup_by_name_len(name, nlen, vrf_id)) != NULL)
+ if ((ifp = if_lookup_by_name(name, vrf_id)) != NULL)
return ifp;
/* hunt the primary interface name... */
- while (seppos < nlen && name[seppos] != ':')
- seppos++;
+ cp = strchr(name, ':');
+ if (cp)
+ *cp = '\0';
- /* Wont catch seperator as last char, e.g. 'foo0:' but thats invalid */
- if (seppos < nlen)
- return if_get_by_name_len(name, seppos, vrf_id, 1);
- else
- return if_get_by_name_len(name, nlen, vrf_id, 1);
+ return if_get_by_name(name, vrf_id, 1);
}
#endif /* SUNOS_5 */
const char *vrfname = (argc > 2) ? argv[idx_vrf]->arg : NULL;
struct interface *ifp;
- size_t sl;
vrf_id_t vrf_id = VRF_DEFAULT;
- if ((sl = strlen(ifname)) > INTERFACE_NAMSIZ) {
+ if (strlen(ifname) > INTERFACE_NAMSIZ) {
vty_out(vty,
"%% Interface name %s is invalid: length exceeds "
"%d characters\n",
VRF_GET_ID(vrf_id, vrfname);
#ifdef SUNOS_5
- ifp = if_sunwzebra_get(ifname, sl, vrf_id);
+ ifp = if_sunwzebra_get(ifname, vrf_id);
#else
- ifp = if_get_by_name_len(ifname, sl, vrf_id, 1);
+ ifp = if_get_by_name(ifname, vrf_id, 1);
#endif /* SUNOS_5 */
if (!ifp) {
To delete, just set ifindex to IFINDEX_INTERNAL to indicate that the
interface does not exist in the kernel.
*/
- char name[INTERFACE_NAMSIZ + 1];
+ char name[INTERFACE_NAMSIZ];
/* Interface index (should be IFINDEX_INTERNAL for non-kernel or
deleted interfaces). */
extern int if_cmp_name_func(char *, char *);
extern void if_update_to_new_vrf(struct interface *, vrf_id_t vrf_id);
-extern struct interface *if_create(const char *name, int namelen,
- vrf_id_t vrf_id);
+extern struct interface *if_create(const char *name, vrf_id_t vrf_id);
extern struct interface *if_lookup_by_index(ifindex_t, vrf_id_t vrf_id);
extern struct interface *if_lookup_exact_address(void *matchaddr, int family,
vrf_id_t vrf_id);
by a '\0' character: */
extern struct interface *if_lookup_by_name_all_vrf(const char *ifname);
extern struct interface *if_lookup_by_name(const char *ifname, vrf_id_t vrf_id);
-extern struct interface *if_get_by_name(const char *ifname, vrf_id_t vrf_id);
-
-/* For these 2 functions, the namelen argument should be the precise length
- of the ifname string (not counting any optional trailing '\0' character).
- In most cases, strnlen should be used to calculate the namelen value. */
-extern struct interface *if_lookup_by_name_len(const char *ifname,
- size_t namelen, vrf_id_t vrf_id);
-extern struct interface *if_get_by_name_len(const char *ifname, size_t namelen,
- vrf_id_t vrf_id, int vty);
-
+extern struct interface *if_get_by_name(const char *ifname, vrf_id_t vrf_id,
+ int vty);
/* Delete the interface, but do not free the structure, and leave it in the
interface list. It is often advisable to leave the pseudo interface
stream_get(ifname_tmp, s, INTERFACE_NAMSIZ);
/* Lookup/create interface by name. */
- ifp = if_get_by_name_len(
- ifname_tmp, strnlen(ifname_tmp, INTERFACE_NAMSIZ), vrf_id, 0);
+ ifp = if_get_by_name(ifname_tmp, vrf_id, 0);
zebra_interface_if_set_value(s, ifp);
stream_get(ifname_tmp, s, INTERFACE_NAMSIZ);
/* Lookup this by interface index. */
- ifp = if_lookup_by_name_len(
- ifname_tmp, strnlen(ifname_tmp, INTERFACE_NAMSIZ), vrf_id);
+ ifp = if_lookup_by_name(ifname_tmp, vrf_id);
if (ifp == NULL) {
zlog_warn("INTERFACE_STATE: Cannot find IF %s in VRF %d",
ifname_tmp, vrf_id);
u_int32_t area_id;
/* find/create ospf6 interface */
- ifp = if_get_by_name(argv[idx_ifname]->arg, VRF_DEFAULT);
+ ifp = if_get_by_name(argv[idx_ifname]->arg, VRF_DEFAULT, 0);
oi = (struct ospf6_interface *)ifp->info;
if (oi == NULL)
oi = ospf6_interface_create(ifp);
{
struct ospf_interface *voi;
struct interface *vi;
- char ifname[INTERFACE_NAMSIZ + 1];
+ char ifname[INTERFACE_NAMSIZ];
struct ospf_area *area;
struct in_addr area_id;
struct connected *co;
ospf->vrf_id);
snprintf(ifname, sizeof(ifname), "VLINK%d", vlink_count);
- vi = if_create(ifname, strnlen(ifname, sizeof(ifname)), ospf->vrf_id);
+ vi = if_create(ifname, ospf->vrf_id);
/*
* if_create sets ZEBRA_INTERFACE_LINKDETECTION
* virtual links don't need this.
return CMD_SUCCESS;
}
- ifp = if_get_by_name(argv[1]->arg, ospf->vrf_id);
+ ifp = if_get_by_name(argv[1]->arg, ospf->vrf_id, 0);
if (ifp == NULL) {
vty_out(vty, "interface %s not found.\n",
(char *)argv[1]->arg);
return CMD_SUCCESS;
}
- ifp = if_get_by_name(argv[2]->arg, ospf->vrf_id);
+ ifp = if_get_by_name(argv[2]->arg, ospf->vrf_id, 0);
if (ifp == NULL) {
vty_out(vty, "interface %s not found.\n",
(char *)argv[1]->arg);
stream_get(ifname_tmp, s, INTERFACE_NAMSIZ);
/* And look it up. */
- return if_lookup_by_name_len(
- ifname_tmp, strnlen(ifname_tmp, INTERFACE_NAMSIZ), vrf_id);
+ return if_lookup_by_name(ifname_tmp, vrf_id);
}
static int ospf_interface_state_up(int command, struct zclient *zclient,
*/
void pim_if_create_pimreg(struct pim_instance *pim)
{
- char pimreg_name[100];
+ char pimreg_name[INTERFACE_NAMSIZ];
if (!pim->regiface) {
if (pim->vrf_id == VRF_DEFAULT)
- strcpy(pimreg_name, "pimreg");
+ strlcpy(pimreg_name, "pimreg", sizeof(pimreg_name));
else
- sprintf(pimreg_name, "pimreg%d",
- pim->vrf->data.l.table_id);
+ snprintf(pimreg_name, sizeof(pimreg_name), "pimreg%u",
+ pim->vrf->data.l.table_id);
- pim->regiface = if_create(pimreg_name, strlen(pimreg_name),
- pim->vrf_id);
+ pim->regiface = if_create(pimreg_name, pim->vrf_id);
pim->regiface->ifindex = PIM_OIF_PIM_REGISTER_VIF;
pim_if_new(pim->regiface, 0, 0);
unsigned int size;
ifreq = (struct ifreq *)((caddr_t)ifconf.ifc_req + n);
- ifp = if_get_by_name_len(
- ifreq->ifr_name,
- strnlen(ifreq->ifr_name, sizeof(ifreq->ifr_name)),
- VRF_DEFAULT, 0);
+ ifp = if_get_by_name(ifreq->ifr_name, VRF_DEFAULT, 0);
if_add_update(ifp);
size = ifreq->ifr_addr.sa_len;
if (size < sizeof(ifreq->ifr_addr))
}
#else
for (n = 0; n < ifconf.ifc_len; n += sizeof(struct ifreq)) {
- ifp = if_get_by_name_len(
- ifreq->ifr_name,
- strnlen(ifreq->ifr_name, sizeof(ifreq->ifr_name)),
- VRF_DEFAULT, 0);
+ ifp = if_get_by_name(ifreq->ifr_name, VRF_DEFAULT, 0);
if_add_update(ifp);
ifreq++;
}
&& (*(lifreq->lifr_name + normallen) != ':'))
normallen++;
- ifp = if_get_by_name_len(lifreq->lifr_name, normallen,
- VRF_DEFAULT, 0);
+ ifp = if_get_by_name(lifreq->lifr_name, VRF_DEFAULT, 0);
if (lifreq->lifr_addr.ss_family == AF_INET)
ifp->flags |= IFF_IPV4;
link_ifindex = *(ifindex_t *)RTA_DATA(tb[IFLA_LINK]);
/* Add interface. */
- ifp = if_get_by_name(name, vrf_id);
+ ifp = if_get_by_name(name, vrf_id, 0);
set_ifindex(ifp, ifi->ifi_index, zns);
ifp->flags = ifi->ifi_flags & 0x0000fffff;
if (IS_ZEBRA_IF_VRF(ifp))
if (ifp == NULL) {
/* unknown interface */
- ifp = if_get_by_name(name, vrf_id);
+ ifp = if_get_by_name(name, vrf_id, 0);
} else {
/* pre-configured interface, learnt now */
if (ifp->vrf_id != vrf_id)
__func__, ifan->ifan_index, ifan->ifan_name);
/* Create Interface */
- ifp = if_get_by_name_len(
- ifan->ifan_name,
- strnlen(ifan->ifan_name, sizeof(ifan->ifan_name)),
- VRF_DEFAULT, 0);
+ ifp = if_get_by_name(ifan->ifan_name, VRF_DEFAULT, 0);
ifp->ifindex = ifan->ifan_index;
if_get_metric(ifp);
if (ifp == NULL) {
/* Interface that zebra was not previously aware of, so
* create. */
- ifp = if_create(ifname, ifnlen, VRF_DEFAULT);
+ ifp = if_create(ifname, VRF_DEFAULT);
if (IS_ZEBRA_DEBUG_KERNEL)
zlog_debug("%s: creating ifp for ifindex %d",
__func__, ifm->ifm_index);