vrrpd: get sockets working

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
This commit is contained in:
Quentin Young 2018-12-04 20:42:17 +00:00
parent b6029d6a5f
commit 4074400076
5 changed files with 32 additions and 14 deletions

View File

@ -19,15 +19,16 @@
*/
#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,

View 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;
}

View 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

View File

@ -40,6 +40,7 @@
char backup_config_file[256];
zebra_capabilities_t _caps_p[] = {
ZCAP_NET_RAW,
};
struct zebra_privs_t vrrp_privs = {

View 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);
}