Skip to content

Commit

Permalink
Refactor, simplify since ifi_prev_addr is not used
Browse files Browse the repository at this point in the history
Signed-off-by: Joachim Wiberg <[email protected]>
  • Loading branch information
troglobit committed Mar 18, 2024
1 parent 714ec5f commit 37696d8
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/bridge.c
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ int show_bridge_compat(FILE *fp)

vnum++;
if (!ifi->ifi_querier) {
inet_fmt(ifi->ifi_curr_addr, s1, sizeof(s1));
inet_fmt(ifi->ifi_address, s1, sizeof(s1));
fprintf(fp, "%4d %-15s LOCAL\n", vid, s1);
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ struct ifi *config_find_ifaddr(in_addr_t addr)
struct ifi *ifi;

TAILQ_FOREACH(ifi, &ifaces, ifi_link) {
if (addr == ifi->ifi_curr_addr)
if (addr == ifi->ifi_address)
return ifi;
}

Expand Down
22 changes: 10 additions & 12 deletions src/iface.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ void iface_exit(void)
void iface_zero(struct ifi *ifi)
{
ifi->ifi_flags = IFIF_DISABLED;
ifi->ifi_curr_addr = 0;
ifi->ifi_address = 0;
ifi->ifi_vlan = 0;
ifi->ifi_name[0] = '\0';
TAILQ_INIT(&ifi->ifi_static);
Expand Down Expand Up @@ -139,19 +139,18 @@ void iface_check_election(struct ifi *ifi)
curr = cand;
}

if (curr != ifi->ifi_curr_addr) {
if (curr != ifi->ifi_address) {
logit(LOG_INFO, 0, "Using %s address %s", ifi->ifi_name, inet_fmt(curr, s1, sizeof(s1)));
ifi->ifi_prev_addr = ifi->ifi_curr_addr;
ifi->ifi_curr_addr = curr;
ifi->ifi_address = curr;
}

if (curr && ifi->ifi_querier) {
uint32_t cur = ifi->ifi_querier->al_addr;

if (ntohl(ifi->ifi_curr_addr) < ntohl(cur)) {
if (ntohl(ifi->ifi_address) < ntohl(cur)) {
inet_fmt(cur, s1, sizeof(s1));
logit(LOG_DEBUG, 0, "New local querier on %s, was %s (%u vs %u)",
ifi->ifi_name, s1, ntohl(ifi->ifi_curr_addr), ntohl(cur));
ifi->ifi_name, s1, ntohl(ifi->ifi_address), ntohl(cur));
pev_timer_del(ifi->ifi_querier->al_timerid);
free(ifi->ifi_querier);
ifi->ifi_querier = NULL;
Expand Down Expand Up @@ -228,8 +227,7 @@ void iface_del(int ifindex, int flags)
free(pa);
}

ifi->ifi_prev_addr = 0;
ifi->ifi_curr_addr = 0;
ifi->ifi_address = 0;
ifi->ifi_index = 0;
ifi->ifi_flags |= IFIF_DOWN;
}
Expand Down Expand Up @@ -322,7 +320,7 @@ static void send_query(struct ifi *ifi, uint32_t dst, int code, uint32_t group)
logit(LOG_DEBUG, 0, "Sending %squery on %s src %s",
(ifi->ifi_flags & IFIF_IGMPV1) ? "v1 " :
(ifi->ifi_flags & IFIF_IGMPV2) ? "v2 " : "v3 ",
ifi->ifi_name, inet_name(ifi->ifi_curr_addr, 1));
ifi->ifi_name, inet_name(ifi->ifi_address, 1));

send_igmp(ifi, dst, IGMP_MEMBERSHIP_QUERY, code, group, datalen);
}
Expand Down Expand Up @@ -433,7 +431,7 @@ void accept_membership_query(int ifindex, uint32_t src, uint32_t dst, uint32_t g
}

if (ifi->ifi_querier == NULL || ifi->ifi_querier->al_addr != src) {
uint32_t cur = ifi->ifi_querier ? ifi->ifi_querier->al_addr : ifi->ifi_curr_addr;
uint32_t cur = ifi->ifi_querier ? ifi->ifi_querier->al_addr : ifi->ifi_address;

/*
* This might be:
Expand Down Expand Up @@ -476,7 +474,7 @@ void accept_membership_query(int ifindex, uint32_t src, uint32_t dst, uint32_t g
* address, go back and fix. We do not consider a
* link-local address better than, e.g., a 192.168.
*/
if (IN_LINKLOCAL(ntohl(ifi->ifi_curr_addr)) && !IN_LINKLOCAL(ntohl(src)))
if (IN_LINKLOCAL(ntohl(ifi->ifi_address)) && !IN_LINKLOCAL(ntohl(src)))
goto again;
}
#if 0
Expand All @@ -503,7 +501,7 @@ void accept_membership_query(int ifindex, uint32_t src, uint32_t dst, uint32_t g
* the [Max Response Time] in the packet.
*/
if (!(ifi->ifi_flags & (IFIF_IGMPV1|IFIF_IGMP_QUERIER))
&& group != 0 && src != ifi->ifi_curr_addr) {
&& group != 0 && src != ifi->ifi_address) {
struct listaddr *g;

logit(LOG_DEBUG, 0, "Group-specific membership query for %s from %s on %s, timer %d",
Expand Down
3 changes: 1 addition & 2 deletions src/iface.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ struct ifi {
uint32_t ifi_vlan; /* Raw VLAN ID for send and accept */
char ifi_name[IFNAMSIZ]; /* interface name */
int ifi_index; /* Primarily for Linux systems */
uint32_t ifi_curr_addr; /* Current address of this interface */
uint32_t ifi_prev_addr; /* Previous address of this interace */
uint32_t ifi_address; /* Current address of this interface */
uint32_t ifi_query_interval; /* IGMP query interval */
struct listaddr *ifi_querier; /* IGMP querier (one or none) */
int ifi_timerid; /* IGMP query timer */
Expand Down
2 changes: 1 addition & 1 deletion src/igmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ size_t build_igmp(uint8_t *buf, uint32_t src, uint32_t dst, int type, int code,
*/
void send_igmp(const struct ifi *ifi, uint32_t dst, int type, int code, uint32_t group, int datalen)
{
uint32_t src = ifi->ifi_curr_addr;
uint32_t src = ifi->ifi_address;
struct sockaddr_ll sll = { 0 };
struct ip *ip;
size_t len;
Expand Down
2 changes: 1 addition & 1 deletion src/ipc.c
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ static int show_igmp_iface(FILE *fp)
int version;

if (!ifi->ifi_querier) {
inet_fmt(ifi->ifi_curr_addr, s1, sizeof(s1));
inet_fmt(ifi->ifi_address, s1, sizeof(s1));
snprintf(timeout, sizeof(timeout), "None ");
} else {
time_t t;
Expand Down

0 comments on commit 37696d8

Please sign in to comment.