Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0129aaae authored by Maciej Żenczykowski's avatar Maciej Żenczykowski
Browse files

libnetutils/packet.c - fix a raw socket reception race



A socket created bound to a specific protocol can receive packets before
it's bound to a specific interface/mac.

It's best to rely on the bind().

This replicates the way packet sockets are created in external/android-clat.
See: ring.c ring_create() and clatd.c configure_packet_socket()

Test: builds, atest
Bug: 155297277
Signed-off-by: default avatarMaciej Żenczykowski <maze@google.com>
Change-Id: I569d2b81a396f352ab5d1b71bd5ad0d96217aab1
parent b7f370c0
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -40,7 +40,7 @@
int fatal(const char*);

int open_raw_socket(const char* ifname __unused, uint8_t hwaddr[ETH_ALEN], int if_index) {
    int s = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_IP));
    int s = socket(PF_PACKET, SOCK_DGRAM, 0);
    if (s < 0) return fatal("socket(PF_PACKET)");

    struct sockaddr_ll bindaddr = {