mirror of
https://github.com/troglobit/finit.git
synced 2026-11-13 17:00:16 +00:00
Drop UDP packets from unwanted interfaces
Previously UDP packets were never dropped and if a request came from a not valid interface inetd got stuck in an inifinite loop looking at the same packet every time and not dropping it. Signed-off-by: Lennart Eriksson <lennart.eriksson@westermo.se>
This commit is contained in:
1 parent
8e55a76732
commit
0c75e59b77
1 file changed
+18
+18
@@ -70,6 +70,22 @@ static int inetd_dgram_peek(int sd, char *ifname)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Peek into SOCK_DGRAM socket to figure out where an inbound packet comes from. */
|
||||||
|
static void inetd_dgram_drop(int sd, const char *ifname)
|
||||||
|
{
|
||||||
|
char pkt_interface[17];
|
||||||
|
char buf[BUFSIZ];
|
||||||
|
|
||||||
|
do {
|
||||||
|
inetd_dgram_peek(sd, pkt_interface);
|
||||||
|
if(string_compare(pkt_interface, ifname)) {
|
||||||
|
recv(sd, buf, sizeof(buf), 0);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
} while (0);
|
||||||
|
}
|
||||||
|
|
||||||
/* Peek into SOCK_STREAM on accepted client socket to figure out inbound interface */
|
/* Peek into SOCK_STREAM on accepted client socket to figure out inbound interface */
|
||||||
static int inetd_stream_peek(int sd, char *ifname)
|
static int inetd_stream_peek(int sd, char *ifname)
|
||||||
{
|
{
|
||||||
@@ -129,6 +145,8 @@ static int get_stdin(svc_t *svc)
|
|||||||
logit(LOG_INFO, "Service %s on %s:%d is not allowed", svc->inetd.name, ifname, svc->inetd.port);
|
logit(LOG_INFO, "Service %s on %s:%d is not allowed", svc->inetd.name, ifname, svc->inetd.port);
|
||||||
if (svc->inetd.type == SOCK_STREAM)
|
if (svc->inetd.type == SOCK_STREAM)
|
||||||
close(stdin);
|
close(stdin);
|
||||||
|
else
|
||||||
|
inetd_dgram_drop(stdin, ifname);
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user