mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-08-02 17:01:49 +00:00
vrrpd, lib: style fixes
Fixup: * Blank lines after declarations * Trailing whitespace * Braces and parentheses Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
This commit is contained in:
parent
4edac1f75f
commit
2fff50ec01
@ -149,7 +149,7 @@ const char *node_names[] = {
|
||||
"bfd", /* BFD_NODE */
|
||||
"bfd peer", /* BFD_PEER_NODE */
|
||||
"openfabric", // OPENFABRIC_NODE
|
||||
"vrrp", // VRRP_NODE
|
||||
"vrrp", /* VRRP_NODE */
|
||||
};
|
||||
/* clang-format on */
|
||||
|
||||
|
@ -57,7 +57,7 @@ struct ipaddr {
|
||||
#define SET_IPADDR_V6(p) (p)->ipa_type = IPADDR_V6
|
||||
|
||||
#define IPADDRSZ(p) \
|
||||
IS_IPADDR_V4((p)) ? sizeof(struct in_addr) : sizeof(struct in6_addr)
|
||||
(IS_IPADDR_V4((p)) ? sizeof(struct in_addr) : sizeof(struct in6_addr))
|
||||
|
||||
static inline int str2ipaddr(const char *str, struct ipaddr *ip)
|
||||
{
|
||||
|
@ -61,7 +61,8 @@ extern void json_object_string_add(struct json_object *obj, const char *key,
|
||||
const char *s);
|
||||
extern void json_object_int_add(struct json_object *obj, const char *key,
|
||||
int64_t i);
|
||||
void json_object_boolean_add(struct json_object *obj, const char *key, bool val);
|
||||
void json_object_boolean_add(struct json_object *obj, const char *key,
|
||||
bool val);
|
||||
extern void json_object_boolean_false_add(struct json_object *obj,
|
||||
const char *key);
|
||||
extern void json_object_boolean_true_add(struct json_object *obj,
|
||||
|
57
vrrpd/vrrp.c
57
vrrpd/vrrp.c
@ -100,6 +100,7 @@ static void vrrp_recalculate_timers(struct vrrp_router *r)
|
||||
uint16_t mdiadv = r->vr->version == 3 ? r->master_adver_interval
|
||||
: r->vr->advertisement_interval;
|
||||
uint16_t skm = (r->vr->version == 3) ? r->master_adver_interval : 100;
|
||||
|
||||
r->skew_time = ((256 - r->vr->priority) * skm) / 256;
|
||||
r->master_down_interval = 3 * mdiadv;
|
||||
r->master_down_interval += r->skew_time;
|
||||
@ -167,6 +168,7 @@ static bool vrrp_ifp_has_vrrp_mac(struct interface *ifp)
|
||||
{
|
||||
struct ethaddr vmac4;
|
||||
struct ethaddr vmac6;
|
||||
|
||||
vrrp_mac_set(&vmac4, 0, 0x00);
|
||||
vrrp_mac_set(&vmac6, 1, 0x00);
|
||||
|
||||
@ -293,7 +295,8 @@ void vrrp_check_start(struct vrrp_vrouter *vr)
|
||||
#endif
|
||||
/* Must have at least one VIP configured */
|
||||
start = start && r->addrs->count > 0;
|
||||
whynot = (!start && !whynot) ? "No Virtual IP address configured" : NULL;
|
||||
whynot =
|
||||
(!start && !whynot) ? "No Virtual IP address configured" : NULL;
|
||||
if (start)
|
||||
vrrp_event(r, VRRP_EVENT_STARTUP);
|
||||
else if (whynot)
|
||||
@ -322,14 +325,18 @@ void vrrp_check_start(struct vrrp_vrouter *vr)
|
||||
start = start && CHECK_FLAG(r->mvl_ifp->flags, IFF_UP);
|
||||
/* Macvlan interface must have a link local */
|
||||
start = start && connected_get_linklocal(r->mvl_ifp);
|
||||
whynot = (!start && !whynot) ? "No link local address configured" : NULL;
|
||||
whynot =
|
||||
(!start && !whynot) ? "No link local address configured" : NULL;
|
||||
/* Macvlan interface must have a v6 IP besides the link local */
|
||||
start = start && (r->mvl_ifp->connected->count >= 2);
|
||||
whynot = (!start && !whynot) ? "No Virtual IP configured on macvlan device" : NULL;
|
||||
whynot = (!start && !whynot)
|
||||
? "No Virtual IP configured on macvlan device"
|
||||
: NULL;
|
||||
#endif
|
||||
/* Must have at least one VIP configured */
|
||||
start = start && r->addrs->count > 0;
|
||||
whynot = (!start && !whynot) ? "No Virtual IP address configured" : NULL;
|
||||
whynot =
|
||||
(!start && !whynot) ? "No Virtual IP address configured" : NULL;
|
||||
if (start)
|
||||
vrrp_event(r, VRRP_EVENT_STARTUP);
|
||||
else if (whynot)
|
||||
@ -381,6 +388,7 @@ int vrrp_add_ip(struct vrrp_router *r, struct ipaddr *ip)
|
||||
|
||||
if (!vrrp_is_owner(r->vr->ifp, ip) && r->is_owner) {
|
||||
char ipbuf[INET6_ADDRSTRLEN];
|
||||
|
||||
inet_ntop(r->family, &ip->ip, ipbuf, sizeof(ipbuf));
|
||||
zlog_err(
|
||||
VRRP_LOGPFX VRRP_LOGPFX_VRID VRRP_LOGPFX_FAM
|
||||
@ -411,6 +419,7 @@ int vrrp_add_ip(struct vrrp_router *r, struct ipaddr *ip)
|
||||
int vrrp_add_ipv4(struct vrrp_vrouter *vr, struct in_addr v4)
|
||||
{
|
||||
struct ipaddr ip;
|
||||
|
||||
ip.ipa_type = IPADDR_V4;
|
||||
ip.ipaddr_v4 = v4;
|
||||
return vrrp_add_ip(vr->v4, &ip);
|
||||
@ -421,6 +430,7 @@ int vrrp_add_ipv6(struct vrrp_vrouter *vr, struct in6_addr v6)
|
||||
assert(vr->version != 2);
|
||||
|
||||
struct ipaddr ip;
|
||||
|
||||
ip.ipa_type = IPADDR_V6;
|
||||
ip.ipaddr_v6 = v6;
|
||||
return vrrp_add_ip(vr->v6, &ip);
|
||||
@ -454,6 +464,7 @@ int vrrp_del_ip(struct vrrp_router *r, struct ipaddr *ip)
|
||||
int vrrp_del_ipv6(struct vrrp_vrouter *vr, struct in6_addr v6)
|
||||
{
|
||||
struct ipaddr ip;
|
||||
|
||||
ip.ipa_type = IPADDR_V6;
|
||||
ip.ipaddr_v6 = v6;
|
||||
return vrrp_del_ip(vr->v6, &ip);
|
||||
@ -462,6 +473,7 @@ int vrrp_del_ipv6(struct vrrp_vrouter *vr, struct in6_addr v6)
|
||||
int vrrp_del_ipv4(struct vrrp_vrouter *vr, struct in_addr v4)
|
||||
{
|
||||
struct ipaddr ip;
|
||||
|
||||
ip.ipa_type = IPADDR_V4;
|
||||
ip.ipaddr_v4 = v4;
|
||||
return vrrp_del_ip(vr->v4, &ip);
|
||||
@ -473,6 +485,7 @@ int vrrp_del_ipv4(struct vrrp_vrouter *vr, struct in_addr v4)
|
||||
static void vrrp_router_addr_list_del_cb(void *val)
|
||||
{
|
||||
struct ipaddr *ip = val;
|
||||
|
||||
XFREE(MTYPE_VRRP_IP, ip);
|
||||
}
|
||||
|
||||
@ -490,6 +503,7 @@ static bool vrrp_attach_interface(struct vrrp_router *r)
|
||||
{
|
||||
/* Search for existing interface with computed MAC address */
|
||||
struct interface **ifps;
|
||||
|
||||
size_t ifps_cnt = if_lookup_by_hwaddr(
|
||||
r->vmac.octet, sizeof(r->vmac.octet), &ifps, VRF_DEFAULT);
|
||||
|
||||
@ -502,6 +516,7 @@ static bool vrrp_attach_interface(struct vrrp_router *r)
|
||||
*/
|
||||
unsigned int candidates = 0;
|
||||
struct interface *selection = NULL;
|
||||
|
||||
for (unsigned int i = 0; i < ifps_cnt; i++) {
|
||||
if (ifps[i]->link_ifindex != r->vr->ifp->ifindex)
|
||||
ifps[i] = NULL;
|
||||
@ -515,6 +530,7 @@ static bool vrrp_attach_interface(struct vrrp_router *r)
|
||||
XFREE(MTYPE_TMP, ifps);
|
||||
|
||||
char ethstr[ETHER_ADDR_STRLEN];
|
||||
|
||||
prefix_mac2str(&r->vmac, ethstr, sizeof(ethstr));
|
||||
|
||||
assert(!!selection == !!candidates);
|
||||
@ -563,12 +579,10 @@ static void vrrp_router_destroy(struct vrrp_router *r)
|
||||
if (r->is_active)
|
||||
vrrp_event(r, VRRP_EVENT_SHUTDOWN);
|
||||
|
||||
if (r->sock_rx >= 0) {
|
||||
if (r->sock_rx >= 0)
|
||||
close(r->sock_rx);
|
||||
}
|
||||
if (r->sock_tx >= 0) {
|
||||
if (r->sock_tx >= 0)
|
||||
close(r->sock_tx);
|
||||
}
|
||||
|
||||
/* FIXME: also delete list elements */
|
||||
list_delete(&r->addrs);
|
||||
@ -617,6 +631,7 @@ void vrrp_vrouter_destroy(struct vrrp_vrouter *vr)
|
||||
struct vrrp_vrouter *vrrp_lookup(struct interface *ifp, uint8_t vrid)
|
||||
{
|
||||
struct vrrp_vrouter vr;
|
||||
|
||||
vr.vrid = vrid;
|
||||
vr.ifp = ifp;
|
||||
|
||||
@ -657,6 +672,7 @@ static int vrrp_bind_to_primary_connected(struct vrrp_router *r)
|
||||
|
||||
struct listnode *ln;
|
||||
struct connected *c = NULL;
|
||||
|
||||
for (ALL_LIST_ELEMENTS_RO(ifp->connected, ln, c))
|
||||
if (c->address->family == r->family) {
|
||||
if (r->family == AF_INET6
|
||||
@ -674,6 +690,7 @@ static int vrrp_bind_to_primary_connected(struct vrrp_router *r)
|
||||
}
|
||||
|
||||
union sockunion su;
|
||||
|
||||
memset(&su, 0x00, sizeof(su));
|
||||
|
||||
switch (r->family) {
|
||||
@ -792,11 +809,13 @@ static int vrrp_recv_advertisement(struct vrrp_router *r, struct ipaddr *src,
|
||||
struct vrrp_pkt *pkt, size_t pktsize)
|
||||
{
|
||||
char sipstr[INET6_ADDRSTRLEN];
|
||||
ipaddr2str(src, sipstr, sizeof(sipstr));
|
||||
char dipstr[INET6_ADDRSTRLEN];
|
||||
|
||||
ipaddr2str(src, sipstr, sizeof(sipstr));
|
||||
ipaddr2str(&r->src, dipstr, sizeof(dipstr));
|
||||
|
||||
char dumpbuf[BUFSIZ];
|
||||
|
||||
vrrp_pkt_adver_dump(dumpbuf, sizeof(dumpbuf), pkt);
|
||||
DEBUGD(&vrrp_dbg_proto,
|
||||
VRRP_LOGPFX VRRP_LOGPFX_VRID VRRP_LOGPFX_FAM
|
||||
@ -950,6 +969,7 @@ static int vrrp_read(struct thread *thread)
|
||||
|
||||
struct msghdr m;
|
||||
struct iovec iov;
|
||||
|
||||
iov.iov_base = r->ibuf;
|
||||
iov.iov_len = sizeof(r->ibuf);
|
||||
m.msg_name = &sa;
|
||||
@ -1038,6 +1058,7 @@ static int vrrp_socket(struct vrrp_router *r)
|
||||
|
||||
if (r->sock_rx < 0 || r->sock_tx < 0) {
|
||||
const char *rxtx = r->sock_rx < 0 ? "Rx" : "Tx";
|
||||
|
||||
zlog_warn(VRRP_LOGPFX VRRP_LOGPFX_VRID VRRP_LOGPFX_FAM
|
||||
"Can't create VRRP %s socket",
|
||||
r->vr->vrid, family2str(r->family), rxtx);
|
||||
@ -1049,6 +1070,7 @@ static int vrrp_socket(struct vrrp_router *r)
|
||||
if (r->family == AF_INET) {
|
||||
/* Set Tx socket to always Tx with TTL set to 255 */
|
||||
int ttl = 255;
|
||||
|
||||
ret = setsockopt(r->sock_tx, IPPROTO_IP, IP_MULTICAST_TTL, &ttl,
|
||||
sizeof(ttl));
|
||||
if (ret < 0) {
|
||||
@ -1087,6 +1109,7 @@ static int vrrp_socket(struct vrrp_router *r)
|
||||
|
||||
/* Bind Rx socket to v4 multicast address */
|
||||
struct sockaddr_in sa = {0};
|
||||
|
||||
sa.sin_family = AF_INET;
|
||||
sa.sin_addr.s_addr = htonl(VRRP_MCASTV4_GROUP);
|
||||
if (bind(r->sock_rx, (struct sockaddr *)&sa, sizeof(sa))) {
|
||||
@ -1106,6 +1129,7 @@ static int vrrp_socket(struct vrrp_router *r)
|
||||
/* Join Rx socket to VRRP IPv4 multicast group */
|
||||
struct connected *c = listhead(r->vr->ifp->connected)->data;
|
||||
struct in_addr v4 = c->address->u.prefix4;
|
||||
|
||||
ret = setsockopt_ipv4_multicast(r->sock_rx, IP_ADD_MEMBERSHIP,
|
||||
v4, htonl(VRRP_MCASTV4_GROUP),
|
||||
r->vr->ifp->ifindex);
|
||||
@ -1123,6 +1147,7 @@ static int vrrp_socket(struct vrrp_router *r)
|
||||
|
||||
/* Set outgoing interface for advertisements */
|
||||
struct ip_mreqn mreqn = {};
|
||||
|
||||
mreqn.imr_ifindex = r->mvl_ifp->ifindex;
|
||||
ret = setsockopt(r->sock_tx, IPPROTO_IP, IP_MULTICAST_IF,
|
||||
(void *)&mreqn, sizeof(mreqn));
|
||||
@ -1195,6 +1220,7 @@ static int vrrp_socket(struct vrrp_router *r)
|
||||
|
||||
/* Bind Rx socket to v6 multicast address */
|
||||
struct sockaddr_in6 sa = {0};
|
||||
|
||||
sa.sin6_family = AF_INET6;
|
||||
inet_pton(AF_INET6, VRRP_MCASTV6_GROUP_STR, &sa.sin6_addr);
|
||||
if (bind(r->sock_rx, (struct sockaddr *)&sa, sizeof(sa))) {
|
||||
@ -1213,6 +1239,7 @@ static int vrrp_socket(struct vrrp_router *r)
|
||||
|
||||
/* Join VRRP IPv6 multicast group */
|
||||
struct ipv6_mreq mreq;
|
||||
|
||||
inet_pton(AF_INET6, VRRP_MCASTV6_GROUP_STR,
|
||||
&mreq.ipv6mr_multiaddr);
|
||||
mreq.ipv6mr_interface = r->vr->ifp->ifindex;
|
||||
@ -1271,7 +1298,7 @@ done:
|
||||
|
||||
/* State machine ----------------------------------------------------------- */
|
||||
|
||||
DEFINE_HOOK(vrrp_change_state_hook, (struct vrrp_router * r, int to), (r, to));
|
||||
DEFINE_HOOK(vrrp_change_state_hook, (struct vrrp_router *r, int to), (r, to));
|
||||
|
||||
/*
|
||||
* Handle any necessary actions during state change to MASTER state.
|
||||
@ -1490,6 +1517,7 @@ static int vrrp_startup(struct vrrp_router *r)
|
||||
/* Create socket */
|
||||
if (r->sock_rx < 0 || r->sock_tx < 0) {
|
||||
int ret = vrrp_socket(r);
|
||||
|
||||
if (ret < 0 || r->sock_tx < 0 || r->sock_rx < 0)
|
||||
return ret;
|
||||
}
|
||||
@ -1499,8 +1527,8 @@ static int vrrp_startup(struct vrrp_router *r)
|
||||
|
||||
/* Configure effective priority */
|
||||
struct ipaddr *primary = (struct ipaddr *)listhead(r->addrs)->data;
|
||||
|
||||
char ipbuf[INET6_ADDRSTRLEN];
|
||||
|
||||
inet_ntop(r->family, &primary->ip.addr, ipbuf, sizeof(ipbuf));
|
||||
|
||||
if (r->vr->priority == VRRP_PRIO_MASTER
|
||||
@ -2191,9 +2219,8 @@ void vrrp_if_address_del(struct interface *ifp)
|
||||
* in this function should be protected by a check that the interface
|
||||
* is up.
|
||||
*/
|
||||
if (if_is_operative(ifp)) {
|
||||
if (if_is_operative(ifp))
|
||||
vrrp_autoconfig_if_address_del(ifp);
|
||||
}
|
||||
}
|
||||
|
||||
/* Other ------------------------------------------------------------------- */
|
||||
@ -2240,6 +2267,7 @@ int vrrp_config_write_interface(struct vty *vty)
|
||||
|
||||
for (ALL_LIST_ELEMENTS_RO(vr->v4->addrs, ipln, ip)) {
|
||||
char ipbuf[INET6_ADDRSTRLEN];
|
||||
|
||||
ipaddr2str(ip, ipbuf, sizeof(ipbuf));
|
||||
vty_out(vty, " vrrp %" PRIu8 " ip %s\n", vr->vrid,
|
||||
ipbuf);
|
||||
@ -2248,6 +2276,7 @@ int vrrp_config_write_interface(struct vty *vty)
|
||||
|
||||
for (ALL_LIST_ELEMENTS_RO(vr->v6->addrs, ipln, ip)) {
|
||||
char ipbuf[INET6_ADDRSTRLEN];
|
||||
|
||||
ipaddr2str(ip, ipbuf, sizeof(ipbuf));
|
||||
vty_out(vty, " vrrp %" PRIu8 " ipv6 %s\n", vr->vrid,
|
||||
ipbuf);
|
||||
@ -2293,8 +2322,8 @@ int vrrp_config_write_global(struct vty *vty)
|
||||
static unsigned int vrrp_hash_key(void *arg)
|
||||
{
|
||||
struct vrrp_vrouter *vr = arg;
|
||||
|
||||
char key[IFNAMSIZ + 64];
|
||||
|
||||
snprintf(key, sizeof(key), "%s@%" PRIu8, vr->ifp->name, vr->vrid);
|
||||
|
||||
return string_hash_make(key);
|
||||
|
@ -464,7 +464,7 @@ extern const char *vrrp_event_names[2];
|
||||
* Use this if you need to react to state changes to perform non-critical
|
||||
* tasks. Critical tasks should go in the internal state change handlers.
|
||||
*/
|
||||
DECLARE_HOOK(vrrp_change_state_hook, (struct vrrp_router * r, int to), (r, to));
|
||||
DECLARE_HOOK(vrrp_change_state_hook, (struct vrrp_router *r, int to), (r, to));
|
||||
|
||||
/*
|
||||
* Trigger a VRRP event on a given Virtual Router..
|
||||
|
@ -35,7 +35,7 @@ struct debug vrrp_dbg_sock = {0, "VRRP sockets"};
|
||||
struct debug vrrp_dbg_zebra = {0, "VRRP Zebra events"};
|
||||
|
||||
struct debug *vrrp_debugs[] = {
|
||||
&vrrp_dbg_arp,
|
||||
&vrrp_dbg_arp,
|
||||
&vrrp_dbg_auto,
|
||||
&vrrp_dbg_ndisc,
|
||||
&vrrp_dbg_pkt,
|
||||
|
@ -57,7 +57,7 @@ struct zebra_privs_t vrrp_privs = {
|
||||
.cap_num_p = array_size(_caps_p),
|
||||
.cap_num_i = 0};
|
||||
|
||||
struct option longopts[] = {{0}};
|
||||
struct option longopts[] = {};
|
||||
|
||||
/* Master of threads. */
|
||||
struct thread_master *master;
|
||||
|
@ -4,7 +4,7 @@
|
||||
* Quentin Young
|
||||
*
|
||||
* Portions:
|
||||
* Copyright (C) 2001-2017 Alexandre Cassen
|
||||
* Copyright (C) 2001-2017 Alexandre Cassen
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the Free
|
||||
@ -134,6 +134,7 @@ static int vrrp_ndisc_una_build(struct interface *ifp, struct ipaddr *ip,
|
||||
uint32_t len = sizeof(struct nd_neighbor_advert)
|
||||
+ sizeof(struct nd_opt_hdr) + ETH_ALEN;
|
||||
struct ipv6_ph ph = {};
|
||||
|
||||
ph.src = ip6h->ip6_src;
|
||||
ph.dst = ip6h->ip6_dst;
|
||||
ph.ulpl = htonl(len);
|
||||
@ -149,8 +150,8 @@ int vrrp_ndisc_una_send(struct vrrp_router *r, struct ipaddr *ip)
|
||||
|
||||
int ret = 0;
|
||||
struct interface *ifp = r->mvl_ifp;
|
||||
|
||||
uint8_t buf[VRRP_NDISC_SIZE];
|
||||
|
||||
ret = vrrp_ndisc_una_build(ifp, ip, buf, sizeof(buf));
|
||||
|
||||
if (ret == -1)
|
||||
@ -167,6 +168,7 @@ int vrrp_ndisc_una_send(struct vrrp_router *r, struct ipaddr *ip)
|
||||
sll.sll_ifindex = (int)ifp->ifindex;
|
||||
|
||||
char ipbuf[INET6_ADDRSTRLEN];
|
||||
|
||||
ipaddr2str(ip, ipbuf, sizeof(ipbuf));
|
||||
|
||||
DEBUGD(&vrrp_dbg_ndisc,
|
||||
|
@ -76,10 +76,12 @@ static uint16_t vrrp_pkt_checksum(struct vrrp_pkt *pkt, size_t pktsize,
|
||||
bool v6 = (src->ipa_type == IPADDR_V6);
|
||||
|
||||
uint16_t chksum_pre = pkt->hdr.chksum;
|
||||
|
||||
pkt->hdr.chksum = 0;
|
||||
|
||||
if (v6) {
|
||||
struct ipv6_ph ph = {};
|
||||
|
||||
ph.src = src->ipaddr_v6;
|
||||
inet_pton(AF_INET6, VRRP_MCASTV6_GROUP_STR, &ph.dst);
|
||||
ph.ulpl = htons(pktsize);
|
||||
@ -87,6 +89,7 @@ static uint16_t vrrp_pkt_checksum(struct vrrp_pkt *pkt, size_t pktsize,
|
||||
chksum = in_cksum_with_ph6(&ph, pkt, pktsize);
|
||||
} else if (!v6 && ((pkt->hdr.vertype >> 4) == 3)) {
|
||||
struct ipv4_ph ph = {};
|
||||
|
||||
ph.src = src->ipaddr_v4;
|
||||
inet_pton(AF_INET, VRRP_MCASTV4_GROUP_STR, &ph.dst);
|
||||
ph.proto = 112;
|
||||
@ -121,6 +124,7 @@ ssize_t vrrp_pkt_adver_build(struct vrrp_pkt **pkt, struct ipaddr *src,
|
||||
assert(!(version == 2 && v6));
|
||||
|
||||
size_t pktsize = VRRP_PKT_SIZE(v6 ? AF_INET6 : AF_INET, version, numip);
|
||||
|
||||
*pkt = XCALLOC(MTYPE_VRRP_PKT, pktsize);
|
||||
|
||||
(*pkt)->hdr.vertype |= version << 4;
|
||||
@ -229,10 +233,12 @@ ssize_t vrrp_pkt_parse_datagram(int family, int version, struct msghdr *m,
|
||||
|
||||
/* Extract source address */
|
||||
struct sockaddr_in *sa = m->msg_name;
|
||||
|
||||
src->ipa_type = IPADDR_V4;
|
||||
src->ipaddr_v4 = sa->sin_addr;
|
||||
} else if (family == AF_INET6) {
|
||||
struct cmsghdr *c;
|
||||
|
||||
for (c = CMSG_FIRSTHDR(m); c != NULL; CMSG_NXTHDR(m, c)) {
|
||||
if (c->cmsg_level == IPPROTO_IPV6
|
||||
&& c->cmsg_type == IPV6_HOPLIMIT)
|
||||
@ -242,6 +248,7 @@ ssize_t vrrp_pkt_parse_datagram(int family, int version, struct msghdr *m,
|
||||
VRRP_PKT_VCHECK(!!c, "IPv6 Hop Limit not received");
|
||||
|
||||
uint8_t *hoplimit = CMSG_DATA(c);
|
||||
|
||||
VRRP_PKT_VCHECK(*hoplimit == 255,
|
||||
"IPv6 Hop Limit is %" PRIu8 "; should be 255",
|
||||
*hoplimit);
|
||||
@ -251,6 +258,7 @@ ssize_t vrrp_pkt_parse_datagram(int family, int version, struct msghdr *m,
|
||||
|
||||
/* Extract source address */
|
||||
struct sockaddr_in6 *sa = m->msg_name;
|
||||
|
||||
src->ipa_type = IPADDR_V6;
|
||||
memcpy(&src->ipaddr_v6, &sa->sin6_addr,
|
||||
sizeof(struct in6_addr));
|
||||
@ -272,10 +280,12 @@ ssize_t vrrp_pkt_parse_datagram(int family, int version, struct msghdr *m,
|
||||
|
||||
/* Version check */
|
||||
uint8_t pktver = (*pkt)->hdr.vertype >> 4;
|
||||
|
||||
VRRP_PKT_VCHECK(pktver == version, "Bad version %u", pktver);
|
||||
|
||||
/* Checksum check */
|
||||
uint16_t chksum = vrrp_pkt_checksum(*pkt, pktsize, src);
|
||||
|
||||
VRRP_PKT_VCHECK((*pkt)->hdr.chksum == chksum,
|
||||
"Bad VRRP checksum %" PRIx16 "; should be %" PRIx16 "",
|
||||
(*pkt)->hdr.chksum, chksum);
|
||||
@ -286,6 +296,7 @@ ssize_t vrrp_pkt_parse_datagram(int family, int version, struct msghdr *m,
|
||||
|
||||
/* Exact size check */
|
||||
size_t ves = VRRP_PKT_SIZE(family, pktver, (*pkt)->hdr.naddr);
|
||||
|
||||
VRRP_PKT_VCHECK(pktsize == ves, "Packet has incorrect # addresses%s",
|
||||
pktver == 2 ? " or missing auth fields" : "");
|
||||
|
||||
@ -298,6 +309,7 @@ ssize_t vrrp_pkt_parse_datagram(int family, int version, struct msghdr *m,
|
||||
/* Addresses check */
|
||||
char vbuf[INET6_ADDRSTRLEN];
|
||||
uint8_t *p = (uint8_t *)(*pkt)->addrs;
|
||||
|
||||
for (uint8_t i = 0; i < (*pkt)->hdr.naddr; i++) {
|
||||
VRRP_PKT_VCHECK(inet_ntop(family, p, vbuf, sizeof(vbuf)),
|
||||
"Bad IP address, #%" PRIu8, i);
|
||||
|
@ -52,7 +52,7 @@
|
||||
(unsigned int)_vrid); \
|
||||
return CMD_WARNING_CONFIG_FAILED; \
|
||||
} \
|
||||
} while (0);
|
||||
} while (0)
|
||||
|
||||
/* clang-format off */
|
||||
|
||||
@ -177,19 +177,20 @@ DEFPY(vrrp_ip,
|
||||
bool activated = false;
|
||||
bool failed = false;
|
||||
int ret = CMD_SUCCESS;
|
||||
int oldstate;
|
||||
|
||||
VROUTER_GET_VTY(vty, ifp, vrid, vr);
|
||||
|
||||
bool will_activate = (vr->v4->fsm.state == VRRP_STATE_INITIALIZE);
|
||||
|
||||
if (no) {
|
||||
int oldstate = vr->v4->fsm.state;
|
||||
oldstate = vr->v4->fsm.state;
|
||||
failed = vrrp_del_ipv4(vr, ip);
|
||||
vrrp_check_start(vr);
|
||||
deactivated = (vr->v4->fsm.state == VRRP_STATE_INITIALIZE
|
||||
&& oldstate != VRRP_STATE_INITIALIZE);
|
||||
} else {
|
||||
int oldstate = vr->v4->fsm.state;
|
||||
oldstate = vr->v4->fsm.state;
|
||||
failed = vrrp_add_ipv4(vr, ip);
|
||||
vrrp_check_start(vr);
|
||||
activated = (vr->v4->fsm.state != VRRP_STATE_INITIALIZE
|
||||
@ -230,6 +231,7 @@ DEFPY(vrrp_ip6,
|
||||
bool activated = false;
|
||||
bool failed = false;
|
||||
int ret = CMD_SUCCESS;
|
||||
int oldstate;
|
||||
|
||||
VROUTER_GET_VTY(vty, ifp, vrid, vr);
|
||||
|
||||
@ -242,13 +244,13 @@ DEFPY(vrrp_ip6,
|
||||
bool will_activate = (vr->v6->fsm.state == VRRP_STATE_INITIALIZE);
|
||||
|
||||
if (no) {
|
||||
int oldstate = vr->v6->fsm.state;
|
||||
oldstate = vr->v6->fsm.state;
|
||||
failed = vrrp_del_ipv6(vr, ipv6);
|
||||
vrrp_check_start(vr);
|
||||
deactivated = (vr->v6->fsm.state == VRRP_STATE_INITIALIZE
|
||||
&& oldstate != VRRP_STATE_INITIALIZE);
|
||||
} else {
|
||||
int oldstate = vr->v6->fsm.state;
|
||||
oldstate = vr->v6->fsm.state;
|
||||
failed = vrrp_add_ipv6(vr, ipv6);
|
||||
vrrp_check_start(vr);
|
||||
activated = (vr->v6->fsm.state != VRRP_STATE_INITIALIZE
|
||||
@ -535,6 +537,7 @@ static void vrrp_show(struct vty *vty, struct vrrp_vrouter *vr)
|
||||
ttable_add_row(tt, "%s|%u", "IPv4 Addresses", vr->v4->addrs->count);
|
||||
|
||||
char fill[35];
|
||||
|
||||
memset(fill, '.', sizeof(fill));
|
||||
fill[sizeof(fill) - 1] = 0x00;
|
||||
if (vr->v4->addrs->count) {
|
||||
@ -556,6 +559,7 @@ static void vrrp_show(struct vty *vty, struct vrrp_vrouter *vr)
|
||||
}
|
||||
|
||||
char *table = ttable_dump(tt, "\n");
|
||||
|
||||
vty_out(vty, "\n%s\n", table);
|
||||
XFREE(MTYPE_TMP, table);
|
||||
ttable_del(tt);
|
||||
|
@ -32,7 +32,7 @@
|
||||
|
||||
#define VRRP_LOGPFX "[ZEBRA] "
|
||||
|
||||
static struct zclient *zclient = NULL;
|
||||
static struct zclient *zclient;
|
||||
|
||||
static void vrrp_zebra_debug_if_state(struct interface *ifp, vrf_id_t vrf_id,
|
||||
const char *func)
|
||||
|
@ -1406,7 +1406,7 @@ int netlink_protodown(struct interface *ifp, bool down)
|
||||
char buf[NL_PKT_BUF_SIZE];
|
||||
} req;
|
||||
|
||||
memset(&req, 0, sizeof req);
|
||||
memset(&req, 0, sizeof(req));
|
||||
|
||||
req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg));
|
||||
req.n.nlmsg_flags = NLM_F_REQUEST;
|
||||
@ -1415,8 +1415,8 @@ int netlink_protodown(struct interface *ifp, bool down)
|
||||
|
||||
req.ifa.ifi_index = ifp->ifindex;
|
||||
|
||||
addattr_l(&req.n, sizeof req, IFLA_PROTO_DOWN, &down, 4);
|
||||
addattr_l(&req.n, sizeof req, IFLA_LINK, &ifp->ifindex, 4);
|
||||
addattr_l(&req.n, sizeof(req), IFLA_PROTO_DOWN, &down, 4);
|
||||
addattr_l(&req.n, sizeof(req), IFLA_LINK, &ifp->ifindex, 4);
|
||||
|
||||
return netlink_talk(netlink_talk_filter, &req.n, &zns->netlink_cmd, zns,
|
||||
0);
|
||||
|
Loading…
Reference in New Issue
Block a user