diff --git a/src/ifset.c b/src/ifset.c index 1294be8..ba1a220 100644 --- a/src/ifset.c +++ b/src/ifset.c @@ -467,7 +467,7 @@ static ssize_t rtnl_if_mtu_set(int fd, unsigned int mtu) int perform_ifup(void) { - int fd = socket(AF_NETLINK, SOCK_DGRAM, NETLINK_ROUTE); + int fd = socket(AF_NETLINK, SOCK_DGRAM | SOCK_NONBLOCK, NETLINK_ROUTE); if (fd < 0) { log_line("%s: (%s) netlink socket open failed: %s", client_config.interface, __func__, strerror(errno)); @@ -525,7 +525,7 @@ void perform_ip_subnet_bcast(const char *str_ipaddr, bcast.s_addr = ipaddr.s_addr | htonl(0xfffffffflu >> prefixlen); } - fd = socket(AF_NETLINK, SOCK_DGRAM, NETLINK_ROUTE); + fd = socket(AF_NETLINK, SOCK_DGRAM | SOCK_NONBLOCK, NETLINK_ROUTE); if (fd < 0) { log_error("%s: (%s) netlink socket open failed: %s", client_config.interface, __func__, strerror(errno)); @@ -584,7 +584,7 @@ void perform_router(const char *str_router, size_t len) return; } - int fd = socket(AF_NETLINK, SOCK_DGRAM, NETLINK_ROUTE); + int fd = socket(AF_NETLINK, SOCK_DGRAM | SOCK_NONBLOCK, NETLINK_ROUTE); if (fd < 0) { log_error("%s: (%s) netlink socket open failed: %s", client_config.interface, __func__, strerror(errno)); @@ -633,7 +633,7 @@ void perform_mtu(const char *str, size_t len) } unsigned int mtu = (unsigned int)tmtu; - int fd = socket(AF_NETLINK, SOCK_DGRAM, NETLINK_ROUTE); + int fd = socket(AF_NETLINK, SOCK_DGRAM | SOCK_NONBLOCK, NETLINK_ROUTE); if (fd < 0) { log_error("%s: (%s) netlink socket open failed: %s", client_config.interface, __func__, strerror(errno)); diff --git a/src/nl.c b/src/nl.c index 45e2666..b45be75 100644 --- a/src/nl.c +++ b/src/nl.c @@ -256,21 +256,11 @@ int nl_sendgetaddr6(int fd, int seq, int ifindex) int nl_open(int nltype, int nlgroup, int *nlportid) { int fd; - fd = socket(AF_NETLINK, SOCK_RAW, nltype); + fd = socket(AF_NETLINK, SOCK_RAW | SOCK_NONBLOCK | SOCK_CLOEXEC, nltype); if (fd < 0) { log_error("%s: socket failed: %s", __func__, strerror(errno)); return -1; } - if (fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_NONBLOCK) < 0) { - log_error("%s: Set non-blocking failed: %s", - __func__, strerror(errno)); - goto err_close; - } - if (fcntl(fd, F_SETFD, FD_CLOEXEC)) { - log_error("%s: Set close-on-exec failed: %s", - __func__, strerror(errno)); - goto err_close; - } socklen_t al; struct sockaddr_nl nlsock = { .nl_family = AF_NETLINK, diff --git a/src/sockd.c b/src/sockd.c index ec46cc9..31b1be2 100644 --- a/src/sockd.c +++ b/src/sockd.c @@ -115,7 +115,7 @@ int request_sockd_fd(char *buf, size_t buflen, char *response) static int create_arp_socket(void) { - int fd = socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ARP)); + int fd = socket(AF_PACKET, SOCK_RAW | SOCK_NONBLOCK, htons(ETH_P_ARP)); if (fd < 0) { log_error("%s: (%s) socket failed: %s", client_config.interface, __func__, strerror(errno)); @@ -154,7 +154,7 @@ static int create_arp_socket(void) static int create_udp_socket(uint32_t ip, uint16_t port, char *iface) { int fd; - if ((fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) { + if ((fd = socket(AF_INET, SOCK_DGRAM | SOCK_NONBLOCK, IPPROTO_UDP)) < 0) { log_error("%s: (%s) socket failed: %s", client_config.interface, __func__, strerror(errno)); goto out; @@ -211,7 +211,8 @@ static int create_raw_socket(struct sockaddr_ll *sa, bool *using_bpf, const struct sock_fprog *filter_prog) { int fd; - if ((fd = socket(AF_PACKET, SOCK_DGRAM, htons(ETH_P_IP))) < 0) { + if ((fd = socket(AF_PACKET, SOCK_DGRAM | SOCK_NONBLOCK, + htons(ETH_P_IP))) < 0) { log_error("create_raw_socket: socket failed: %s", strerror(errno)); goto out; }