mirror of
https://gitlab.isc.org/isc-projects/dhcp
synced 2025-09-03 15:56:00 +00:00
Add code to read and discard incoming packets on fallback socket
This commit is contained in:
@@ -280,7 +280,10 @@ void dispatch ()
|
|||||||
for (l = interfaces; l; l = l -> next) {
|
for (l = interfaces; l; l = l -> next) {
|
||||||
++nfds;
|
++nfds;
|
||||||
}
|
}
|
||||||
fds = (struct pollfd *)malloc (nfds * sizeof (struct pollfd));
|
#ifdef USE_FALLBACK
|
||||||
|
++nfds;
|
||||||
|
#endif
|
||||||
|
fds = (struct pollfd *)malloc ((nfds) * sizeof (struct pollfd));
|
||||||
if (!fds)
|
if (!fds)
|
||||||
error ("Can't allocate poll structures.");
|
error ("Can't allocate poll structures.");
|
||||||
|
|
||||||
@@ -292,6 +295,13 @@ void dispatch ()
|
|||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef USE_FALLBACK
|
||||||
|
fds [i].fd = fallback_interface.wfdesc;
|
||||||
|
fds [i].events = POLLIN;
|
||||||
|
fds [i].revents = 0;
|
||||||
|
++i;
|
||||||
|
#endif
|
||||||
|
|
||||||
do {
|
do {
|
||||||
/* Wait for a packet or a timeout... XXX */
|
/* Wait for a packet or a timeout... XXX */
|
||||||
count = poll (fds, nfds, -1);
|
count = poll (fds, nfds, -1);
|
||||||
@@ -310,6 +320,10 @@ void dispatch ()
|
|||||||
fds [i].revents = 0;
|
fds [i].revents = 0;
|
||||||
got_one (l);
|
got_one (l);
|
||||||
}
|
}
|
||||||
|
#ifdef USE_FALLBACK
|
||||||
|
if (fds [i].revents & POLLIN)
|
||||||
|
fallback_discard (&fallback_interface);
|
||||||
|
#endif
|
||||||
} while (1);
|
} while (1);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
@@ -337,6 +351,12 @@ void dispatch ()
|
|||||||
if (l -> rfdesc > max)
|
if (l -> rfdesc > max)
|
||||||
max = l -> rfdesc;
|
max = l -> rfdesc;
|
||||||
}
|
}
|
||||||
|
#ifdef USE_FALLBACK
|
||||||
|
FD_SET (fallback_interface.wfdesc, &r);
|
||||||
|
FD_SET (fallback_interface.wfdesc, &w);
|
||||||
|
if (fallback_interface.wfdesc > max)
|
||||||
|
max = fallback_interface.wfdesc;
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Wait for a packet or a timeout... XXX */
|
/* Wait for a packet or a timeout... XXX */
|
||||||
count = select (max + 1, &r, &w, &x, (struct timeval *)0);
|
count = select (max + 1, &r, &w, &x, (struct timeval *)0);
|
||||||
@@ -353,6 +373,10 @@ void dispatch ()
|
|||||||
continue;
|
continue;
|
||||||
got_one (l);
|
got_one (l);
|
||||||
}
|
}
|
||||||
|
#ifdef USE_FALLBACK
|
||||||
|
if (FD_ISSET (fallback_interface.wfdesc, &r))
|
||||||
|
fallback_discard (&fallback_interface);
|
||||||
|
#endif
|
||||||
} while (1);
|
} while (1);
|
||||||
}
|
}
|
||||||
#endif /* USE_POLL */
|
#endif /* USE_POLL */
|
||||||
|
@@ -182,3 +182,18 @@ size_t receive_packet (interface, buf, len, from, hfrom)
|
|||||||
(struct sockaddr *)from, &flen);
|
(struct sockaddr *)from, &flen);
|
||||||
}
|
}
|
||||||
#endif /* USE_SOCKET_RECEIVE */
|
#endif /* USE_SOCKET_RECEIVE */
|
||||||
|
|
||||||
|
#ifdef USE_SOCKET_FALLBACK
|
||||||
|
/* This just reads in a packet and silently discards it. */
|
||||||
|
|
||||||
|
size_t fallback_discard (interface)
|
||||||
|
struct interface_info *interface;
|
||||||
|
{
|
||||||
|
char buf [1540];
|
||||||
|
struct sockaddr_in from;
|
||||||
|
int flen = sizeof from;
|
||||||
|
|
||||||
|
return recvfrom (interface -> wfdesc, buf, sizeof buf, 0,
|
||||||
|
(struct sockaddr *)&from, &flen);
|
||||||
|
}
|
||||||
|
#endif /* USE_SOCKET_RECEIVE */
|
||||||
|
1
dhcpd.h
1
dhcpd.h
@@ -401,6 +401,7 @@ size_t send_fallback PROTO ((struct interface_info *,
|
|||||||
struct packet *, struct dhcp_packet *, size_t,
|
struct packet *, struct dhcp_packet *, size_t,
|
||||||
struct in_addr,
|
struct in_addr,
|
||||||
struct sockaddr_in *, struct hardware *));
|
struct sockaddr_in *, struct hardware *));
|
||||||
|
size_t fallback_discard PROTO ((struct interface_info *));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef USE_SOCKET_SEND
|
#ifdef USE_SOCKET_SEND
|
||||||
|
26
dispatch.c
26
dispatch.c
@@ -280,7 +280,10 @@ void dispatch ()
|
|||||||
for (l = interfaces; l; l = l -> next) {
|
for (l = interfaces; l; l = l -> next) {
|
||||||
++nfds;
|
++nfds;
|
||||||
}
|
}
|
||||||
fds = (struct pollfd *)malloc (nfds * sizeof (struct pollfd));
|
#ifdef USE_FALLBACK
|
||||||
|
++nfds;
|
||||||
|
#endif
|
||||||
|
fds = (struct pollfd *)malloc ((nfds) * sizeof (struct pollfd));
|
||||||
if (!fds)
|
if (!fds)
|
||||||
error ("Can't allocate poll structures.");
|
error ("Can't allocate poll structures.");
|
||||||
|
|
||||||
@@ -292,6 +295,13 @@ void dispatch ()
|
|||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef USE_FALLBACK
|
||||||
|
fds [i].fd = fallback_interface.wfdesc;
|
||||||
|
fds [i].events = POLLIN;
|
||||||
|
fds [i].revents = 0;
|
||||||
|
++i;
|
||||||
|
#endif
|
||||||
|
|
||||||
do {
|
do {
|
||||||
/* Wait for a packet or a timeout... XXX */
|
/* Wait for a packet or a timeout... XXX */
|
||||||
count = poll (fds, nfds, -1);
|
count = poll (fds, nfds, -1);
|
||||||
@@ -310,6 +320,10 @@ void dispatch ()
|
|||||||
fds [i].revents = 0;
|
fds [i].revents = 0;
|
||||||
got_one (l);
|
got_one (l);
|
||||||
}
|
}
|
||||||
|
#ifdef USE_FALLBACK
|
||||||
|
if (fds [i].revents & POLLIN)
|
||||||
|
fallback_discard (&fallback_interface);
|
||||||
|
#endif
|
||||||
} while (1);
|
} while (1);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
@@ -337,6 +351,12 @@ void dispatch ()
|
|||||||
if (l -> rfdesc > max)
|
if (l -> rfdesc > max)
|
||||||
max = l -> rfdesc;
|
max = l -> rfdesc;
|
||||||
}
|
}
|
||||||
|
#ifdef USE_FALLBACK
|
||||||
|
FD_SET (fallback_interface.wfdesc, &r);
|
||||||
|
FD_SET (fallback_interface.wfdesc, &w);
|
||||||
|
if (fallback_interface.wfdesc > max)
|
||||||
|
max = fallback_interface.wfdesc;
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Wait for a packet or a timeout... XXX */
|
/* Wait for a packet or a timeout... XXX */
|
||||||
count = select (max + 1, &r, &w, &x, (struct timeval *)0);
|
count = select (max + 1, &r, &w, &x, (struct timeval *)0);
|
||||||
@@ -353,6 +373,10 @@ void dispatch ()
|
|||||||
continue;
|
continue;
|
||||||
got_one (l);
|
got_one (l);
|
||||||
}
|
}
|
||||||
|
#ifdef USE_FALLBACK
|
||||||
|
if (FD_ISSET (fallback_interface.wfdesc, &r))
|
||||||
|
fallback_discard (&fallback_interface);
|
||||||
|
#endif
|
||||||
} while (1);
|
} while (1);
|
||||||
}
|
}
|
||||||
#endif /* USE_POLL */
|
#endif /* USE_POLL */
|
||||||
|
@@ -401,6 +401,7 @@ size_t send_fallback PROTO ((struct interface_info *,
|
|||||||
struct packet *, struct dhcp_packet *, size_t,
|
struct packet *, struct dhcp_packet *, size_t,
|
||||||
struct in_addr,
|
struct in_addr,
|
||||||
struct sockaddr_in *, struct hardware *));
|
struct sockaddr_in *, struct hardware *));
|
||||||
|
size_t fallback_discard PROTO ((struct interface_info *));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef USE_SOCKET_SEND
|
#ifdef USE_SOCKET_SEND
|
||||||
|
15
socket.c
15
socket.c
@@ -182,3 +182,18 @@ size_t receive_packet (interface, buf, len, from, hfrom)
|
|||||||
(struct sockaddr *)from, &flen);
|
(struct sockaddr *)from, &flen);
|
||||||
}
|
}
|
||||||
#endif /* USE_SOCKET_RECEIVE */
|
#endif /* USE_SOCKET_RECEIVE */
|
||||||
|
|
||||||
|
#ifdef USE_SOCKET_FALLBACK
|
||||||
|
/* This just reads in a packet and silently discards it. */
|
||||||
|
|
||||||
|
size_t fallback_discard (interface)
|
||||||
|
struct interface_info *interface;
|
||||||
|
{
|
||||||
|
char buf [1540];
|
||||||
|
struct sockaddr_in from;
|
||||||
|
int flen = sizeof from;
|
||||||
|
|
||||||
|
return recvfrom (interface -> wfdesc, buf, sizeof buf, 0,
|
||||||
|
(struct sockaddr *)&from, &flen);
|
||||||
|
}
|
||||||
|
#endif /* USE_SOCKET_RECEIVE */
|
||||||
|
Reference in New Issue
Block a user