Skip to content
This repository was archived by the owner on Jan 27, 2019. It is now read-only.

Commit 8bd9762

Browse files
committed
Cleanup RFC Compliant implementation
1. Make vmac and normal modes more integrated 2. Remove unneeded additional variables from vrrp_rt 3. Shutdown vmac interface when going to backup or fault state: this elimenates the need for iptables filters in backup mode 4. Integrate with new patched macvlan driver 5. Listen on the lowerdev of macvlan instead of the macvlan interface requires new macvlan driver with vyatta patch.
1 parent c7dcf49 commit 8bd9762

File tree

10 files changed

+97
-73
lines changed

10 files changed

+97
-73
lines changed

keepalived/include/vrrp.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,11 @@ typedef struct _vrrp_rt {
8989
sa_family_t family; /* AF_INET|AF_INET6 */
9090
char *iname; /* Instance Name */
9191
vrrp_sgroup *sync; /* Sync group we belong to */
92-
interface *ifp; /* Interface we belong to */
93-
unsigned int ifindex; /* ifindex of (parent)interface (if vmac)*/
92+
interface *ifp; /* Interface on which we receive traffic */
93+
interface *xmit_ifp; /* Interface on which we transmit traffic */
94+
unsigned int vmac_ifindex; /* ifindex of the vmac interface used upon deletion */
9495
int dont_track_primary; /* If set ignores ifp faults */
9596
int vmac; /* If set try to set VRRP VMAC */
96-
unsigned int vmac_ifindex; /* ifindex of vmac interface */
9797
char vmac_ifname[IFNAMSIZ]; /* name of vmac interface */
9898
list track_ifp; /* Interface state we monitor */
9999
list track_script; /* Script state we monitor */
@@ -216,7 +216,7 @@ typedef struct _vrrp_rt {
216216
/* prototypes */
217217
extern vrrp_pkt *vrrp_get_header(sa_family_t, char *, int *, uint32_t *);
218218
extern int open_vrrp_send_socket(sa_family_t, int, int);
219-
extern int open_vrrp_socket(sa_family_t, int, int, int);
219+
extern int open_vrrp_socket(sa_family_t, int, int);
220220
extern int new_vrrp_socket(vrrp_rt *);
221221
extern void close_vrrp_socket(vrrp_rt *);
222222
extern void vrrp_send_link_update(vrrp_rt *);

keepalived/include/vrrp_data.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@
4242
typedef struct _sock {
4343
sa_family_t family;
4444
int proto;
45-
int ifindex;
46-
int parent_ifindex; /* store parent if index in vmac case */
45+
int recv_ifindex; /* ifindex of in_fd */
46+
int xmit_ifindex; /* ifindex of out_fd */
4747
int fd_in;
4848
int fd_out;
4949
} sock_t;

keepalived/include/vrrp_vmac.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,7 @@
3838
/* prototypes */
3939
extern int netlink_link_add_vmac(vrrp_rt *);
4040
extern int netlink_link_del_vmac(vrrp_rt *);
41+
extern int netlink_link_down(vrrp_rt *);
42+
extern int netlink_link_up(vrrp_rt *);
4143

4244
#endif

keepalived/vrrp/vrrp.c

Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -715,10 +715,7 @@ void
715715
vrrp_state_become_master(vrrp_rt * vrrp)
716716
{
717717
if (vrrp->vmac) {
718-
if (vrrp->auth_type == VRRP_AUTH_AH)
719-
vyatta_if_drop_iptables_input_filter(IF_NAME(vrrp->ifp), 1);
720-
else
721-
vyatta_if_drop_iptables_input_filter(IF_NAME(vrrp->ifp), 0);
718+
netlink_link_up(vrrp);
722719
}
723720

724721
/* add the ip addresses */
@@ -800,18 +797,9 @@ vrrp_restore_interface(vrrp_rt * vrrp, int advF)
800797
}
801798
if (vrrp->vmac){
802799
if (advF) {
803-
if (vrrp->auth_type == VRRP_AUTH_AH)
804-
vyatta_if_drop_iptables_input_filter(IF_NAME(vrrp->ifp), 1);
805-
else
806-
vyatta_if_drop_iptables_input_filter(IF_NAME(vrrp->ifp), 0);
800+
netlink_link_up(vrrp);
807801
} else {
808-
if (vrrp->auth_type == VRRP_AUTH_AH) {
809-
vyatta_if_drop_iptables_input_filter(IF_NAME(vrrp->ifp), 1);
810-
vyatta_if_create_iptables_input_filter(IF_NAME(vrrp->ifp), 1);
811-
} else {
812-
vyatta_if_drop_iptables_input_filter(IF_NAME(vrrp->ifp), 0);
813-
vyatta_if_create_iptables_input_filter(IF_NAME(vrrp->ifp), 0);
814-
}
802+
netlink_link_down(vrrp);
815803
}
816804
}
817805

@@ -1098,14 +1086,13 @@ open_vrrp_send_socket(sa_family_t family, int proto, int idx)
10981086

10991087
/* open a VRRP socket and join the multicast group. */
11001088
int
1101-
open_vrrp_socket(sa_family_t family, int proto, int idx, int parent_idx)
1089+
open_vrrp_socket(sa_family_t family, int proto, int idx)
11021090
{
1103-
interface *ifp, *parent_ifp;
1091+
interface *ifp;
11041092
int fd = -1;
1105-
1093+
11061094
/* Retreive interface */
11071095
ifp = if_get_by_ifindex(idx);
1108-
parent_ifp = if_get_by_ifindex(parent_idx);
11091096

11101097
/* open the socket */
11111098
fd = socket(family, SOCK_RAW, proto);
@@ -1117,9 +1104,6 @@ open_vrrp_socket(sa_family_t family, int proto, int idx, int parent_idx)
11171104

11181105
/* Join the VRRP MCAST group */
11191106
if_join_vrrp_group(family, &fd, ifp, proto);
1120-
/* Only join on parent interface if its different than the current */
1121-
if (idx != parent_idx)
1122-
if_join_vrrp_group(family, &fd, parent_ifp, proto);
11231107

11241108
if (fd < 0)
11251109
return -1;
@@ -1149,8 +1133,8 @@ new_vrrp_socket(vrrp_rt * vrrp)
11491133
close_vrrp_socket(vrrp);
11501134
remove_vrrp_fd_bucket(vrrp);
11511135
proto = (vrrp->auth_type == VRRP_AUTH_AH) ? IPPROTO_IPSEC_AH : IPPROTO_VRRP;
1152-
vrrp->fd_in = open_vrrp_socket(vrrp->family, proto, IF_INDEX(vrrp->ifp), vrrp->ifindex);
1153-
vrrp->fd_out = open_vrrp_send_socket(vrrp->family, proto, IF_INDEX(vrrp->ifp));
1136+
vrrp->fd_in = open_vrrp_socket(vrrp->family, proto, IF_INDEX(vrrp->ifp));
1137+
vrrp->fd_out = open_vrrp_send_socket(vrrp->family, proto, IF_INDEX(vrrp->xmit_ifp));
11541138
alloc_vrrp_fd_bucket(vrrp);
11551139

11561140
/* Sync the other desc */
@@ -1351,11 +1335,7 @@ clear_diff_vrrp(void)
13511335
clear_diff_vrrp_vroutes(vrrp);
13521336

13531337
if (vrrp->vmac) {
1354-
if (vrrp->auth_type == VRRP_AUTH_AH) {
1355-
vyatta_if_drop_iptables_input_filter(IF_NAME(new_vrrp->ifp), 1);
1356-
} else {
1357-
vyatta_if_drop_iptables_input_filter(IF_NAME(new_vrrp->ifp), 0);
1358-
}
1338+
netlink_link_up(vrrp);
13591339
}
13601340

13611341

keepalived/vrrp/vrrp_data.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ free_sock(void *sock_data)
138138
sock_t *sock = sock_data;
139139
interface *ifp;
140140
if (sock->fd_in > 0) {
141-
ifp = if_get_by_ifindex(sock->ifindex);
141+
ifp = if_get_by_ifindex(sock->recv_ifindex);
142142
if_leave_vrrp_group(sock->family, sock->fd_in, ifp);
143143
}
144144
if (sock->fd_out > 0)
@@ -150,9 +150,9 @@ static void
150150
dump_sock(void *sock_data)
151151
{
152152
sock_t *sock = sock_data;
153-
log_message(LOG_INFO, "VRRP sockpool: [ifindex(%d), parent_ifindex(%d), proto(%d), fd(%d,%d)]"
154-
, sock->ifindex
155-
, sock->parent_ifindex
153+
log_message(LOG_INFO, "VRRP sockpool: [recv_ifindex(%d), xmit_ifindex(%d), proto(%d), fd(%d,%d)]"
154+
, sock->recv_ifindex
155+
, sock->xmit_ifindex
156156
, sock->proto
157157
, sock->fd_in
158158
, sock->fd_out);
@@ -336,13 +336,13 @@ void
336336
alloc_vrrp_vip(vector strvec)
337337
{
338338
vrrp_rt *vrrp = LIST_TAIL_DATA(vrrp_data->vrrp);
339-
if (vrrp->ifp == NULL) {
339+
if (vrrp->xmit_ifp == NULL) {
340340
log_message(LOG_ERR, "Configuration error: VRRP definition must belong to an interface");
341341
}
342342

343343
if (LIST_ISEMPTY(vrrp->vip))
344344
vrrp->vip = alloc_list(free_ipaddress, dump_ipaddress);
345-
alloc_ipaddress(vrrp->vip, strvec, vrrp->ifp);
345+
alloc_ipaddress(vrrp->vip, strvec, vrrp->xmit_ifp);
346346
}
347347
void
348348
alloc_vrrp_evip(vector strvec)

keepalived/vrrp/vrrp_parser.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,6 @@ vrrp_vmac_handler(vector strvec)
107107
vrrp->vmac = 1;
108108
if (!(vrrp->mcast_saddr))
109109
vrrp->mcast_saddr = IF_ADDR(vrrp->ifp);
110-
if (!(vrrp->ifindex))
111-
vrrp->ifindex = IF_INDEX(vrrp->ifp);
112110
if (strvec && (strvec->allocated == 2))
113111
strncpy(vrrp->vmac_ifname, VECTOR_SLOT(strvec, 1),
114112
IFNAMSIZ - 1);
@@ -151,7 +149,7 @@ vrrp_int_handler(vector strvec)
151149
vrrp_rt *vrrp = LIST_TAIL_DATA(vrrp_data->vrrp);
152150
char *name = VECTOR_SLOT(strvec, 1);
153151
vrrp->ifp = if_get_by_ifname(name);
154-
vrrp->ifindex = IF_INDEX(vrrp->ifp); //hold parent if index
152+
vrrp->xmit_ifp = vrrp->ifp;
155153
if (vrrp->vmac && !(vrrp->vmac & 2))
156154
netlink_link_add_vmac(vrrp);
157155
}

keepalived/vrrp/vrrp_scheduler.c

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -418,22 +418,22 @@ already_exist_sock(list l, sa_family_t family, int proto, int ifindex)
418418
sock = ELEMENT_DATA(e);
419419
if ((sock->family == family) &&
420420
(sock->proto == proto) &&
421-
(sock->ifindex == ifindex))
421+
(sock->recv_ifindex == ifindex))
422422
return 1;
423423
}
424424
return 0;
425425
}
426426

427427
void
428-
alloc_sock(sa_family_t family, list l, int proto, int ifindex, int p_ifindex)
428+
alloc_sock(sa_family_t family, list l, int proto, int r_ifindex, int x_ifindex)
429429
{
430430
sock_t *new;
431431

432432
new = (sock_t *) MALLOC(sizeof (sock_t));
433433
new->family = family;
434434
new->proto = proto;
435-
new->ifindex = ifindex;
436-
new->parent_ifindex = p_ifindex;
435+
new->recv_ifindex = r_ifindex;
436+
new->xmit_ifindex = x_ifindex;
437437

438438
list_add(l, new);
439439
}
@@ -444,26 +444,28 @@ vrrp_create_sockpool(list l)
444444
vrrp_rt *vrrp;
445445
list p = vrrp_data->vrrp;
446446
element e;
447-
int ifindex, parent_ifindex;
447+
int recv_ifindex, xmit_ifindex;
448448
int proto;
449449

450450
for (e = LIST_HEAD(p); e; ELEMENT_NEXT(e)) {
451451
vrrp = ELEMENT_DATA(e);
452-
ifindex = IF_INDEX(vrrp->ifp);
453452

454-
if (vrrp->vmac)
455-
parent_ifindex = vrrp->ifindex;
456-
else
457-
parent_ifindex = ifindex;
453+
if (vrrp->vmac) {
454+
recv_ifindex = IF_INDEX(vrrp->ifp);
455+
xmit_ifindex = vrrp->vmac_ifindex;
456+
} else {
457+
recv_ifindex = IF_INDEX(vrrp->ifp);
458+
xmit_ifindex = recv_ifindex;
459+
}
458460

459461
if (vrrp->auth_type == VRRP_AUTH_AH)
460462
proto = IPPROTO_IPSEC_AH;
461463
else
462464
proto = IPPROTO_VRRP;
463465

464466
/* add the vrrp element if not exist */
465-
if (!already_exist_sock(l, vrrp->family, proto, ifindex))
466-
alloc_sock(vrrp->family, l, proto, ifindex, parent_ifindex);
467+
if (!already_exist_sock(l, vrrp->family, proto, recv_ifindex))
468+
alloc_sock(vrrp->family, l, proto, recv_ifindex, xmit_ifindex);
467469
}
468470
}
469471

@@ -476,12 +478,12 @@ vrrp_open_sockpool(list l)
476478
for (e = LIST_HEAD(l); e; ELEMENT_NEXT(e)) {
477479
sock = ELEMENT_DATA(e);
478480
sock->fd_in = open_vrrp_socket(sock->family, sock->proto,
479-
sock->ifindex, sock->parent_ifindex);
481+
sock->recv_ifindex);
480482
if (sock->fd_in == -1)
481483
sock->fd_out = -1;
482484
else
483485
sock->fd_out = open_vrrp_send_socket(sock->family, sock->proto,
484-
sock->ifindex);
486+
sock->xmit_ifindex);
485487
}
486488
}
487489

@@ -504,7 +506,7 @@ vrrp_set_fds(list l)
504506
else
505507
proto = IPPROTO_VRRP;
506508

507-
if ((sock->ifindex == IF_INDEX(vrrp->ifp)) &&
509+
if ((sock->recv_ifindex == IF_INDEX(vrrp->ifp)) &&
508510
(sock->proto == proto)) {
509511
vrrp->fd_in = sock->fd_in;
510512
vrrp->fd_out = sock->fd_out;

keepalived/vrrp/vrrp_snmp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1191,7 +1191,7 @@ vrrp_rfc_snmp_new_master_trap(vrrp_rt *vrrp)
11911191
oid objid_snmptrap[] = { SNMPTRAP_OID };
11921192
size_t objid_snmptrap_len = OID_LENGTH(objid_snmptrap);
11931193
/* OID for trap data vrrpOperMasterIPAddr */
1194-
oid masterip_oid[] = { VRRP_RFC_OID, 1, 3, 1, 7, vrrp->ifindex, vrrp->vrid };
1194+
oid masterip_oid[] = { VRRP_RFC_OID, 1, 3, 1, 7, IF_INDEX(vrrp->ifp), vrrp->vrid };
11951195
size_t masterip_oid_len = OID_LENGTH(masterip_oid);
11961196

11971197
netsnmp_variable_list *notification_vars = NULL;

keepalived/vrrp/vrrp_vmac.c

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,14 @@ netlink_link_setlladdr(vrrp_rt *vrrp)
5151
req.n.nlmsg_flags = NLM_F_REQUEST;
5252
req.n.nlmsg_type = RTM_NEWLINK;
5353
req.ifi.ifi_family = AF_INET;
54-
req.ifi.ifi_index = IF_INDEX(vrrp->ifp);
54+
req.ifi.ifi_index = IF_INDEX(vrrp->xmit_ifp);
5555

5656
addattr_l(&req.n, sizeof(req), IFLA_ADDRESS, ll_addr, ETH_ALEN);
5757

5858
if (netlink_talk(&nl_cmd, &req.n) < 0)
5959
status = -1;
6060
else
61-
memcpy(vrrp->ifp->hw_addr, ll_addr, ETH_ALEN);
61+
memcpy(vrrp->xmit_ifp->hw_addr, ll_addr, ETH_ALEN);
6262

6363
return status;
6464
}
@@ -80,7 +80,7 @@ netlink_link_setmode(vrrp_rt *vrrp)
8080
req.n.nlmsg_flags = NLM_F_REQUEST;
8181
req.n.nlmsg_type = RTM_NEWLINK;
8282
req.ifi.ifi_family = AF_INET;
83-
req.ifi.ifi_index = IF_INDEX(vrrp->ifp);
83+
req.ifi.ifi_index = IF_INDEX(vrrp->xmit_ifp);
8484

8585
linkinfo = NLMSG_TAIL(&req.n);
8686
addattr_l(&req.n, sizeof(req), IFLA_LINKINFO, NULL, 0);
@@ -94,8 +94,11 @@ netlink_link_setmode(vrrp_rt *vrrp)
9494
* In private mode, macvlan will receive frames with same MAC addr
9595
* as configured on the interface.
9696
*/
97+
#ifndef MACVLAN_MODE_VRRP
98+
#define MACVLAN_MODE_VRRP 16
99+
#endif
97100
addattr32(&req.n, sizeof(req), IFLA_MACVLAN_MODE,
98-
MACVLAN_MODE_PRIVATE);
101+
MACVLAN_MODE_VRRP);
99102
data->rta_len = (void *)NLMSG_TAIL(&req.n) - (void *)data;
100103

101104
linkinfo->rta_len = (void *)NLMSG_TAIL(&req.n) - (void *)linkinfo;
@@ -106,7 +109,7 @@ netlink_link_setmode(vrrp_rt *vrrp)
106109
return status;
107110
}
108111

109-
static int
112+
int
110113
netlink_link_up(vrrp_rt *vrrp)
111114
{
112115
int status = 1;
@@ -122,7 +125,7 @@ netlink_link_up(vrrp_rt *vrrp)
122125
req.n.nlmsg_flags = NLM_F_REQUEST;
123126
req.n.nlmsg_type = RTM_NEWLINK;
124127
req.ifi.ifi_family = AF_UNSPEC;
125-
req.ifi.ifi_index = IF_INDEX(vrrp->ifp);
128+
req.ifi.ifi_index = IF_INDEX(vrrp->xmit_ifp);
126129
req.ifi.ifi_change |= IFF_UP;
127130
req.ifi.ifi_flags |= IFF_UP;
128131

@@ -132,6 +135,32 @@ netlink_link_up(vrrp_rt *vrrp)
132135
return status;
133136
}
134137

138+
int
139+
netlink_link_down(vrrp_rt *vrrp)
140+
{
141+
int status = 1;
142+
struct {
143+
struct nlmsghdr n;
144+
struct ifinfomsg ifi;
145+
char buf[256];
146+
} req;
147+
148+
memset(&req, 0, sizeof (req));
149+
150+
req.n.nlmsg_len = NLMSG_LENGTH(sizeof (struct ifinfomsg));
151+
req.n.nlmsg_flags = NLM_F_REQUEST;
152+
req.n.nlmsg_type = RTM_NEWLINK;
153+
req.ifi.ifi_family = AF_UNSPEC;
154+
req.ifi.ifi_index = IF_INDEX(vrrp->xmit_ifp);
155+
req.ifi.ifi_change |= IFF_UP;
156+
req.ifi.ifi_flags &= ~IFF_UP;
157+
158+
if (netlink_talk(&nl_cmd, &req.n) < 0)
159+
status = -1;
160+
161+
return status;
162+
}
163+
135164
int
136165
netlink_link_add_vmac(vrrp_rt *vrrp)
137166
{
@@ -156,9 +185,9 @@ netlink_link_add_vmac(vrrp_rt *vrrp)
156185
* by a previous instance.
157186
*/
158187
if (reload && (ifp = if_get_by_ifname(ifname))) {
159-
vrrp->ifp = ifp;
188+
vrrp->xmit_ifp = ifp;
160189
/* Save ifindex for use on delete */
161-
vrrp->vmac_ifindex = IF_INDEX(vrrp->ifp);
190+
vrrp->vmac_ifindex = IF_INDEX(vrrp->xmit_ifp);
162191
vrrp->vmac |= 2;
163192
return 1;
164193
}
@@ -187,8 +216,8 @@ netlink_link_add_vmac(vrrp_rt *vrrp)
187216
ifp = if_get_by_ifname(ifname);
188217
if (!ifp)
189218
return -1;
190-
vrrp->ifp = ifp;
191-
vrrp->vmac_ifindex = IF_INDEX(vrrp->ifp); /* For use on delete */
219+
vrrp->xmit_ifp = ifp;
220+
vrrp->vmac_ifindex = IF_INDEX(vrrp->xmit_ifp); /* For use on delete */
192221
vrrp->vmac |= 2;
193222
netlink_link_setlladdr(vrrp);
194223
vyatta_if_setup(ifname);

0 commit comments

Comments
 (0)