Skip to content

Commit c532ff7

Browse files
committed
Remove duplicate address family from listener
Since address already contain family, remove separate family from listener. Use now family from address itself.
1 parent 6677cd9 commit c532ff7

File tree

4 files changed

+30
-29
lines changed

4 files changed

+30
-29
lines changed

src/dnsmasq.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ struct irec {
571571
};
572572

573573
struct listener {
574-
int fd, tcpfd, tftpfd, family, used;
574+
int fd, tcpfd, tftpfd, used;
575575
union mysockaddr addr;
576576
struct irec *iface; /* only sometimes valid for non-wildcard */
577577
struct listener *next;

src/forward.c

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1282,8 +1282,9 @@ void receive_query(struct listener *listen, time_t now)
12821282
CMSG_SPACE(sizeof(struct sockaddr_dl))];
12831283
#endif
12841284
} control_u;
1285+
int family = listen->addr.sa.sa_family;
12851286
/* Can always get recvd interface for IPv6 */
1286-
int check_dst = !option_bool(OPT_NOWILD) || listen->family == AF_INET6;
1287+
int check_dst = !option_bool(OPT_NOWILD) || family == AF_INET6;
12871288

12881289
/* packet buffer overwritten */
12891290
daemon->srv_save = NULL;
@@ -1295,7 +1296,7 @@ void receive_query(struct listener *listen, time_t now)
12951296
{
12961297
auth_dns = listen->iface->dns_auth;
12971298

1298-
if (listen->family == AF_INET)
1299+
if (family == AF_INET)
12991300
{
13001301
dst_addr_4 = dst_addr.addr4 = listen->iface->addr.in.sin_addr;
13011302
netmask = listen->iface->netmask;
@@ -1325,9 +1326,9 @@ void receive_query(struct listener *listen, time_t now)
13251326
information disclosure. */
13261327
memset(daemon->packet + n, 0, daemon->edns_pktsz - n);
13271328

1328-
source_addr.sa.sa_family = listen->family;
1329+
source_addr.sa.sa_family = family;
13291330

1330-
if (listen->family == AF_INET)
1331+
if (family == AF_INET)
13311332
{
13321333
/* Source-port == 0 is an error, we can't send back to that.
13331334
http://www.ietf.org/mail-archive/web/dnsop/current/msg11441.html */
@@ -1347,7 +1348,7 @@ void receive_query(struct listener *listen, time_t now)
13471348
{
13481349
struct addrlist *addr;
13491350

1350-
if (listen->family == AF_INET6)
1351+
if (family == AF_INET6)
13511352
{
13521353
for (addr = daemon->interface_addrs; addr; addr = addr->next)
13531354
if ((addr->flags & ADDRLIST_IPV6) &&
@@ -1385,7 +1386,7 @@ void receive_query(struct listener *listen, time_t now)
13851386
return;
13861387

13871388
#if defined(HAVE_LINUX_NETWORK)
1388-
if (listen->family == AF_INET)
1389+
if (family == AF_INET)
13891390
for (cmptr = CMSG_FIRSTHDR(&msg); cmptr; cmptr = CMSG_NXTHDR(&msg, cmptr))
13901391
if (cmptr->cmsg_level == IPPROTO_IP && cmptr->cmsg_type == IP_PKTINFO)
13911392
{
@@ -1398,7 +1399,7 @@ void receive_query(struct listener *listen, time_t now)
13981399
if_index = p.p->ipi_ifindex;
13991400
}
14001401
#elif defined(IP_RECVDSTADDR) && defined(IP_RECVIF)
1401-
if (listen->family == AF_INET)
1402+
if (family == AF_INET)
14021403
{
14031404
for (cmptr = CMSG_FIRSTHDR(&msg); cmptr; cmptr = CMSG_NXTHDR(&msg, cmptr))
14041405
{
@@ -1423,7 +1424,7 @@ void receive_query(struct listener *listen, time_t now)
14231424
}
14241425
#endif
14251426

1426-
if (listen->family == AF_INET6)
1427+
if (family == AF_INET6)
14271428
{
14281429
for (cmptr = CMSG_FIRSTHDR(&msg); cmptr; cmptr = CMSG_NXTHDR(&msg, cmptr))
14291430
if (cmptr->cmsg_level == IPPROTO_IPV6 && cmptr->cmsg_type == daemon->v6pktinfo)
@@ -1444,16 +1445,16 @@ void receive_query(struct listener *listen, time_t now)
14441445
if (!indextoname(listen->fd, if_index, ifr.ifr_name))
14451446
return;
14461447

1447-
if (!iface_check(listen->family, &dst_addr, ifr.ifr_name, &auth_dns))
1448+
if (!iface_check(family, &dst_addr, ifr.ifr_name, &auth_dns))
14481449
{
14491450
if (!option_bool(OPT_CLEVERBIND))
14501451
enumerate_interfaces(0);
1451-
if (!loopback_exception(listen->fd, listen->family, &dst_addr, ifr.ifr_name) &&
1452-
!label_exception(if_index, listen->family, &dst_addr))
1452+
if (!loopback_exception(listen->fd, family, &dst_addr, ifr.ifr_name) &&
1453+
!label_exception(if_index, family, &dst_addr))
14531454
return;
14541455
}
14551456

1456-
if (listen->family == AF_INET && option_bool(OPT_LOCALISE))
1457+
if (family == AF_INET && option_bool(OPT_LOCALISE))
14571458
{
14581459
struct irec *iface;
14591460

@@ -1498,7 +1499,7 @@ void receive_query(struct listener *listen, time_t now)
14981499
#endif
14991500
char *types = querystr(auth_dns ? "auth" : "query", type);
15001501

1501-
if (listen->family == AF_INET)
1502+
if (family == AF_INET)
15021503
log_query(F_QUERY | F_IPV4 | F_FORWARD, daemon->namebuff,
15031504
(union all_addr *)&source_addr.in.sin_addr, types);
15041505
else

src/network.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -964,7 +964,6 @@ static struct listener *create_listeners(union mysockaddr *addr, int do_tftp, in
964964
{
965965
l = safe_malloc(sizeof(struct listener));
966966
l->next = NULL;
967-
l->family = addr->sa.sa_family;
968967
l->fd = fd;
969968
l->tcpfd = tcpfd;
970969
l->tftpfd = tftpfd;

src/tftp.c

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,9 @@ void tftp_request(struct listener *listen, time_t now)
6161
char *prefix = daemon->tftp_prefix;
6262
struct tftp_prefix *pref;
6363
union all_addr addra;
64+
int family = listen->addr.sa.sa_family;
6465
/* Can always get recvd interface for IPv6 */
65-
int check_dest = !option_bool(OPT_NOWILD) || listen->family == AF_INET6;
66+
int check_dest = !option_bool(OPT_NOWILD) || family == AF_INET6;
6667
union {
6768
struct cmsghdr align; /* this ensures alignment */
6869
char control6[CMSG_SPACE(sizeof(struct in6_pktinfo))];
@@ -121,10 +122,10 @@ void tftp_request(struct listener *listen, time_t now)
121122
if (msg.msg_controllen < sizeof(struct cmsghdr))
122123
return;
123124

124-
addr.sa.sa_family = listen->family;
125+
addr.sa.sa_family = family;
125126

126127
#if defined(HAVE_LINUX_NETWORK)
127-
if (listen->family == AF_INET)
128+
if (family == AF_INET)
128129
for (cmptr = CMSG_FIRSTHDR(&msg); cmptr; cmptr = CMSG_NXTHDR(&msg, cmptr))
129130
if (cmptr->cmsg_level == IPPROTO_IP && cmptr->cmsg_type == IP_PKTINFO)
130131
{
@@ -138,7 +139,7 @@ void tftp_request(struct listener *listen, time_t now)
138139
}
139140

140141
#elif defined(HAVE_SOLARIS_NETWORK)
141-
if (listen->family == AF_INET)
142+
if (family == AF_INET)
142143
for (cmptr = CMSG_FIRSTHDR(&msg); cmptr; cmptr = CMSG_NXTHDR(&msg, cmptr))
143144
{
144145
union {
@@ -154,7 +155,7 @@ void tftp_request(struct listener *listen, time_t now)
154155
}
155156

156157
#elif defined(IP_RECVDSTADDR) && defined(IP_RECVIF)
157-
if (listen->family == AF_INET)
158+
if (family == AF_INET)
158159
for (cmptr = CMSG_FIRSTHDR(&msg); cmptr; cmptr = CMSG_NXTHDR(&msg, cmptr))
159160
{
160161
union {
@@ -171,7 +172,7 @@ void tftp_request(struct listener *listen, time_t now)
171172

172173
#endif
173174

174-
if (listen->family == AF_INET6)
175+
if (family == AF_INET6)
175176
{
176177
for (cmptr = CMSG_FIRSTHDR(&msg); cmptr; cmptr = CMSG_NXTHDR(&msg, cmptr))
177178
if (cmptr->cmsg_level == IPPROTO_IPV6 && cmptr->cmsg_type == daemon->v6pktinfo)
@@ -194,7 +195,7 @@ void tftp_request(struct listener *listen, time_t now)
194195

195196
addra.addr4 = addr.in.sin_addr;
196197

197-
if (listen->family == AF_INET6)
198+
if (family == AF_INET6)
198199
addra.addr6 = addr.in6.sin6_addr;
199200

200201
if (daemon->tftp_interfaces)
@@ -210,12 +211,12 @@ void tftp_request(struct listener *listen, time_t now)
210211
else
211212
{
212213
/* Do the same as DHCP */
213-
if (!iface_check(listen->family, &addra, name, NULL))
214+
if (!iface_check(family, &addra, name, NULL))
214215
{
215216
if (!option_bool(OPT_CLEVERBIND))
216217
enumerate_interfaces(0);
217-
if (!loopback_exception(listen->tftpfd, listen->family, &addra, name) &&
218-
!label_exception(if_index, listen->family, &addra))
218+
if (!loopback_exception(listen->tftpfd, family, &addra, name) &&
219+
!label_exception(if_index, family, &addra))
219220
return;
220221
}
221222

@@ -281,7 +282,7 @@ void tftp_request(struct listener *listen, time_t now)
281282
prefix = pref->prefix;
282283
}
283284

284-
if (listen->family == AF_INET)
285+
if (family == AF_INET)
285286
{
286287
addr.in.sin_port = htons(port);
287288
#ifdef HAVE_SOCKADDR_SA_LEN
@@ -304,7 +305,7 @@ void tftp_request(struct listener *listen, time_t now)
304305

305306
if (option_bool(OPT_SINGLE_PORT))
306307
transfer->sockfd = listen->tftpfd;
307-
else if ((transfer->sockfd = socket(listen->family, SOCK_DGRAM, 0)) == -1)
308+
else if ((transfer->sockfd = socket(family, SOCK_DGRAM, 0)) == -1)
308309
{
309310
free(transfer);
310311
return;
@@ -337,7 +338,7 @@ void tftp_request(struct listener *listen, time_t now)
337338
{
338339
if (++port <= daemon->end_tftp_port)
339340
{
340-
if (listen->family == AF_INET)
341+
if (family == AF_INET)
341342
addr.in.sin_port = htons(port);
342343
else
343344
addr.in6.sin6_port = htons(port);
@@ -375,7 +376,7 @@ void tftp_request(struct listener *listen, time_t now)
375376
if ((opt = next(&p, end)) && !option_bool(OPT_TFTP_NOBLOCK))
376377
{
377378
/* 32 bytes for IP, UDP and TFTP headers, 52 bytes for IPv6 */
378-
int overhead = (listen->family == AF_INET) ? 32 : 52;
379+
int overhead = (family == AF_INET) ? 32 : 52;
379380
transfer->blocksize = atoi(opt);
380381
if (transfer->blocksize < 1)
381382
transfer->blocksize = 1;

0 commit comments

Comments
 (0)