]> git.puffer.fish Git - matthieu/frr.git/commitdiff
vrrpd: get sockets working
authorQuentin Young <qlyoung@cumulusnetworks.com>
Tue, 4 Dec 2018 20:42:17 +0000 (20:42 +0000)
committerQuentin Young <qlyoung@cumulusnetworks.com>
Fri, 17 May 2019 00:27:08 +0000 (00:27 +0000)
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
vrrpd/vrrp.c
vrrpd/vrrp_arp.c
vrrpd/vrrp_arp.h
vrrpd/vrrp_main.c
vrrpd/vrrp_vty.c

index bf7da51fde5ea9fe6f8c6f5becf6afad191f3c5d..23f144a792aabe43f7fbfcafe586c17802a89bd5 100644 (file)
  */
 #include <zebra.h>
 
-#include "memory.h"
-#include "if.h"
-#include "linklist.h"
-#include "prefix.h"
-#include "hash.h"
-#include "vrf.h"
-#include "hook.h"
+#include "lib/memory.h"
+#include "lib/if.h"
+#include "lib/linklist.h"
+#include "lib/prefix.h"
+#include "lib/hash.h"
+#include "lib/vrf.h"
+#include "lib/hook.h"
 
 #include "vrrp.h"
+#include "vrrp_arp.h"
 
 /* Utility functions ------------------------------------------------------- */
 
@@ -151,12 +152,14 @@ static int vrrp_socket(struct vrrp_vrouter *vr)
        int ret;
        struct connected *c;
 
-       vr->sock = socket(AF_INET, SOCK_RAW, IPPROTO_VRRP);
-
-       if (vr->sock < 0) {
-               /* FIXME */
+       errno = 0;
+       frr_elevate_privs(&vrrp_privs) {
+               vr->sock = socket(AF_INET, SOCK_RAW, IPPROTO_VRRP);
        }
 
+       if (vr->sock < 0)
+               perror("Error opening VRRP socket");
+
        /* Join the multicast group.*/
 
         /* FIXME: Use first address on the interface and for imr_interface */
@@ -283,6 +286,10 @@ static int vrrp_master_down_timer_expire(struct thread *thread)
  */
 static int vrrp_startup(struct vrrp_vrouter *vr)
 {
+       /* Initialize global gratuitous ARP socket if necessary */
+       if (!vrrp_garp_is_init())
+               vrrp_garp_init();
+
        /* Create socket */
        int ret = vrrp_socket(vr);
        if (ret < 0) {
@@ -295,7 +302,7 @@ static int vrrp_startup(struct vrrp_vrouter *vr)
 
        if (vr->priority == VRRP_PRIO_MASTER) {
                vrrp_send_advertisement(vr);
-               /* FIXME: vrrp_send_gratuitous_arp(vr); */
+               /* vrrp_garp_send(vr); */
 
                thread_add_timer_msec(master, vrrp_adver_timer_expire, vr,
                                      vr->advertisement_interval * 10,
index cbea02212b8a02a3a77f16d80257e64456b02962..a67af4e10472ab271349688fa0ca3a11d47afca3 100644 (file)
@@ -163,11 +163,16 @@ void vrrp_garp_init(void)
 {
        /* Create the socket descriptor */
        /* FIXME: why ETH_P_RARP? */
-       garp_fd = socket(PF_PACKET, SOCK_RAW | SOCK_CLOEXEC, htons(ETH_P_RARP));
+       errno = 0;
+       frr_elevate_privs(&vrrp_privs) {
+               garp_fd = socket(PF_PACKET, SOCK_RAW | SOCK_CLOEXEC,
+                                htons(ETH_P_RARP));
+       }
 
        if (garp_fd > 0)
                zlog_info("Initialized gratuitous ARP socket");
        else {
+               perror("Error initializing gratuitous ARP socket");
                zlog_err("Error initializing gratuitous ARP socket");
                return;
        }
@@ -178,3 +183,8 @@ void vrrp_garp_fini(void)
        close(garp_fd);
        garp_fd = -1;
 }
+
+bool vrrp_garp_is_init(void)
+{
+       return garp_fd > 0;
+}
index d3c5651ab5bc605fd3852a33c63adc5d7cf42d12..57223835ef2dc9ef578c75e0569f63aab39061fe 100644 (file)
@@ -30,6 +30,7 @@
 /* prototypes */
 extern void vrrp_garp_init(void);
 extern void vrrp_garp_fini(void);
+extern bool vrrp_garp_is_init(void);
 extern void vrrp_garp_send(struct vrrp_vrouter *vr, struct in_addr *v4);
 extern void vrrp_garp_send_all(struct vrrp_vrouter *vr);
 #endif
index c470ec365ba95ce1fa5c1f0915eae8c868161b1a..d60f37d8fc92682965b760e5e0c85e7ad8fc22d2 100644 (file)
@@ -40,6 +40,7 @@
 char backup_config_file[256];
 
 zebra_capabilities_t _caps_p[] = {
+       ZCAP_NET_RAW,
 };
 
 struct zebra_privs_t vrrp_privs = {
index 4c5ce7f855981b2d256ec22e979b1cb5695026a1..f30aadd626afe40fe7276bed5432c8c4c65e1cff 100644 (file)
@@ -80,6 +80,5 @@ void vrrp_vty_init(void)
        install_node(&interface_node, NULL);
        if_cmd_init();
        install_element(VIEW_NODE, &show_debugging_vrrpd_cmd);
-       install_element(ENABLE_NODE, &show_debugging_vrrpd_cmd);
        install_element(INTERFACE_NODE, &vrrp_vrid_cmd);
 }