]> git.proxmox.com Git - mirror_frr.git/blobdiff - vrrpd/vrrp.c
vrrpd: allow vrrp_shutdown() on shutdown rtr
[mirror_frr.git] / vrrpd / vrrp.c
index 42bb154f985e988c96d5d1e89ddd9d571a41caaa..7a68b6b829d5f2c2fb0aca0a6626cd00935525c3 100644 (file)
@@ -397,9 +397,10 @@ static bool vrrp_has_ip(struct vrrp_vrouter *vr, struct ipaddr *ip)
        return false;
 }
 
-int vrrp_add_ip(struct vrrp_router *r, struct ipaddr *ip)
+int vrrp_add_ip(struct vrrp_vrouter *vr, struct ipaddr *ip)
 {
-       int af = (ip->ipa_type == IPADDR_V6) ? AF_INET6 : AF_INET;
+       struct vrrp_router *r = IS_IPADDR_V4(ip) ? vr->v4 : vr->v6;
+       int af = r->family;
 
        assert(r->family == af);
        assert(!(r->vr->version == 2 && ip->ipa_type == IPADDR_V6));
@@ -443,7 +444,7 @@ int vrrp_add_ipv4(struct vrrp_vrouter *vr, struct in_addr v4)
 
        ip.ipa_type = IPADDR_V4;
        ip.ipaddr_v4 = v4;
-       return vrrp_add_ip(vr->v4, &ip);
+       return vrrp_add_ip(vr, &ip);
 }
 
 int vrrp_add_ipv6(struct vrrp_vrouter *vr, struct in6_addr v6)
@@ -454,15 +455,19 @@ int vrrp_add_ipv6(struct vrrp_vrouter *vr, struct in6_addr v6)
 
        ip.ipa_type = IPADDR_V6;
        ip.ipaddr_v6 = v6;
-       return vrrp_add_ip(vr->v6, &ip);
+       return vrrp_add_ip(vr, &ip);
 }
 
-int vrrp_del_ip(struct vrrp_router *r, struct ipaddr *ip)
+
+
+int vrrp_del_ip(struct vrrp_vrouter *vr, struct ipaddr *ip)
 {
        struct listnode *ln, *nn;
        struct ipaddr *iter;
        int ret = 0;
 
+       struct vrrp_router *r = IS_IPADDR_V4(ip) ? vr->v4 : vr->v6;
+
        if (!vrrp_has_ip(r->vr, ip))
                return 0;
 
@@ -488,7 +493,7 @@ int vrrp_del_ipv6(struct vrrp_vrouter *vr, struct in6_addr v6)
 
        ip.ipa_type = IPADDR_V6;
        ip.ipaddr_v6 = v6;
-       return vrrp_del_ip(vr->v6, &ip);
+       return vrrp_del_ip(vr, &ip);
 }
 
 int vrrp_del_ipv4(struct vrrp_vrouter *vr, struct in_addr v4)
@@ -497,7 +502,7 @@ int vrrp_del_ipv4(struct vrrp_vrouter *vr, struct in_addr v4)
 
        ip.ipa_type = IPADDR_V4;
        ip.ipaddr_v4 = v4;
-       return vrrp_del_ip(vr->v4, &ip);
+       return vrrp_del_ip(vr, &ip);
 }
 
 
@@ -649,12 +654,12 @@ void vrrp_vrouter_destroy(struct vrrp_vrouter *vr)
        XFREE(MTYPE_VRRP_RTR, vr);
 }
 
-struct vrrp_vrouter *vrrp_lookup(struct interface *ifp, uint8_t vrid)
+struct vrrp_vrouter *vrrp_lookup(const struct interface *ifp, uint8_t vrid)
 {
        struct vrrp_vrouter vr;
 
        vr.vrid = vrid;
-       vr.ifp = ifp;
+       vr.ifp = (struct interface *)ifp;
 
        return hash_lookup(vrrp_vrouters_hash, &vr);
 }
@@ -1410,7 +1415,7 @@ static void vrrp_change_state_initialize(struct vrrp_router *r)
        r->ndisc_pending = false;
 
        /* Disable ND Router Advertisements */
-       if (r->family == AF_INET6)
+       if (r->family == AF_INET6 && r->mvl_ifp)
                vrrp_zebra_radv_set(r, false);
 }
 
@@ -1618,7 +1623,8 @@ static int vrrp_shutdown(struct vrrp_router *r)
        THREAD_OFF(r->t_write);
 
        /* Protodown macvlan */
-       vrrp_zclient_send_interface_protodown(r->mvl_ifp, true);
+       if (r->mvl_ifp)
+               vrrp_zclient_send_interface_protodown(r->mvl_ifp, true);
 
        /* Throw away our source address */
        memset(&r->src, 0x00, sizeof(r->src));