XFREE(MTYPE_TMP, ip);
}
-static struct vrrp_router *vrrp_router_create(struct vrrp_vrouter *vr,
- int family)
+/*
+ * Search for a suitable macvlan subinterface we can attach to, and if found,
+ * attach to it.
+ *
+ * r
+ * Router to attach to interface
+ *
+ * Returns:
+ * Whether an interface was successfully attached
+ */
+static bool vrrp_attach_interface(struct vrrp_router *r)
{
- struct vrrp_router *r = XCALLOC(MTYPE_TMP, sizeof(struct vrrp_router));
-
- r->family = family;
- r->sock_rx = -1;
- r->sock_tx = -1;
- r->vr = vr;
- r->addrs = list_new();
- r->addrs->del = vrrp_router_addr_list_del_cb;
- r->priority = vr->priority;
- r->fsm.state = VRRP_STATE_INITIALIZE;
- vrrp_mac_set(&r->vmac, family == AF_INET6, vr->vrid);
-
/* Search for existing interface with computed MAC address */
struct interface **ifps;
size_t ifps_cnt = if_lookup_by_hwaddr(
unsigned int candidates = 0;
struct interface *selection = NULL;
for (unsigned int i = 0; i < ifps_cnt; i++) {
- zlog_info("Found VRRP interface %s", ifps[i]->name);
if (strncmp(ifps[i]->name, r->vr->ifp->name,
strlen(r->vr->ifp->name)))
ifps[i] = NULL;
if (candidates == 0)
zlog_warn(VRRP_LOGPFX VRRP_LOGPFX_VRID
- "No interface found w/ MAC %s; using default",
+ "No interface found w/ MAC %s",
r->vr->vrid, ethstr);
else if (candidates > 1)
zlog_warn(VRRP_LOGPFX VRRP_LOGPFX_VRID
r->mvl_ifp = selection;
+ return !!r->mvl_ifp;
+
+}
+
+static struct vrrp_router *vrrp_router_create(struct vrrp_vrouter *vr,
+ int family)
+{
+ struct vrrp_router *r = XCALLOC(MTYPE_TMP, sizeof(struct vrrp_router));
+
+ r->family = family;
+ r->sock_rx = -1;
+ r->sock_tx = -1;
+ r->vr = vr;
+ r->addrs = list_new();
+ r->addrs->del = vrrp_router_addr_list_del_cb;
+ r->priority = vr->priority;
+ r->fsm.state = VRRP_STATE_INITIALIZE;
+ vrrp_mac_set(&r->vmac, family == AF_INET6, vr->vrid);
+
+ vrrp_attach_interface(r);
+
return r;
}
return -1;
/* Must have a valid macvlan interface available */
- if (r->mvl_ifp == NULL) {
+ if (r->mvl_ifp == NULL && !vrrp_attach_interface(r)) {
zlog_warn(VRRP_LOGPFX VRRP_LOGPFX_VRID
"No appropriate interface for %s VRRP found",
r->vr->vrid, family2str(r->family));