mirror of
https://github.com/systemd/systemd.git
synced 2024-10-28 20:25:38 +03:00
Merge pull request #16336 from yuwata/ifindex-cleanups
tiny cleanups related to ifindex
This commit is contained in:
commit
63b7e7b4ba
@ -1130,6 +1130,7 @@ int socket_bind_to_ifname(int fd, const char *ifname) {
|
||||
|
||||
int socket_bind_to_ifindex(int fd, int ifindex) {
|
||||
char ifname[IF_NAMESIZE + 1];
|
||||
int r;
|
||||
|
||||
assert(fd >= 0);
|
||||
|
||||
@ -1141,10 +1142,9 @@ int socket_bind_to_ifindex(int fd, int ifindex) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (setsockopt(fd, SOL_SOCKET, SO_BINDTOIFINDEX, &ifindex, sizeof(ifindex)) >= 0)
|
||||
return 0;
|
||||
if (errno != ENOPROTOOPT)
|
||||
return -errno;
|
||||
r = setsockopt_int(fd, SOL_SOCKET, SO_BINDTOIFINDEX, ifindex);
|
||||
if (r != -ENOPROTOOPT)
|
||||
return r;
|
||||
|
||||
/* Fall back to SO_BINDTODEVICE on kernels < 5.0 which didn't have SO_BINDTOIFINDEX */
|
||||
if (!format_ifname(ifindex, ifname))
|
||||
|
@ -112,7 +112,7 @@ int dhcp6_option_parse_ip6addrs(uint8_t *optval, uint16_t optlen,
|
||||
int dhcp6_option_parse_domainname(const uint8_t *optval, uint16_t optlen,
|
||||
char ***str_arr);
|
||||
|
||||
int dhcp6_network_bind_udp_socket(int index, struct in6_addr *address);
|
||||
int dhcp6_network_bind_udp_socket(int ifindex, struct in6_addr *address);
|
||||
int dhcp6_network_send_udp_socket(int s, struct in6_addr *address,
|
||||
const void *packet, size_t len);
|
||||
|
||||
|
@ -17,16 +17,16 @@
|
||||
#include "fd-util.h"
|
||||
#include "socket-util.h"
|
||||
|
||||
int dhcp6_network_bind_udp_socket(int index, struct in6_addr *local_address) {
|
||||
int dhcp6_network_bind_udp_socket(int ifindex, struct in6_addr *local_address) {
|
||||
union sockaddr_union src = {
|
||||
.in6.sin6_family = AF_INET6,
|
||||
.in6.sin6_port = htobe16(DHCP6_PORT_CLIENT),
|
||||
.in6.sin6_scope_id = index,
|
||||
.in6.sin6_scope_id = ifindex,
|
||||
};
|
||||
_cleanup_close_ int s = -1;
|
||||
int r;
|
||||
|
||||
assert(index > 0);
|
||||
assert(ifindex > 0);
|
||||
assert(local_address);
|
||||
|
||||
src.in6.sin6_addr = *local_address;
|
||||
|
@ -81,11 +81,11 @@ static int icmp6_bind_router_message(const struct icmp6_filter *filter,
|
||||
return TAKE_FD(s);
|
||||
}
|
||||
|
||||
int icmp6_bind_router_solicitation(int index) {
|
||||
int icmp6_bind_router_solicitation(int ifindex) {
|
||||
struct icmp6_filter filter = {};
|
||||
struct ipv6_mreq mreq = {
|
||||
.ipv6mr_multiaddr = IN6ADDR_ALL_NODES_MULTICAST_INIT,
|
||||
.ipv6mr_interface = index,
|
||||
.ipv6mr_interface = ifindex,
|
||||
};
|
||||
|
||||
ICMP6_FILTER_SETBLOCKALL(&filter);
|
||||
@ -94,11 +94,11 @@ int icmp6_bind_router_solicitation(int index) {
|
||||
return icmp6_bind_router_message(&filter, &mreq);
|
||||
}
|
||||
|
||||
int icmp6_bind_router_advertisement(int index) {
|
||||
int icmp6_bind_router_advertisement(int ifindex) {
|
||||
struct icmp6_filter filter = {};
|
||||
struct ipv6_mreq mreq = {
|
||||
.ipv6mr_multiaddr = IN6ADDR_ALL_ROUTERS_MULTICAST_INIT,
|
||||
.ipv6mr_interface = index,
|
||||
.ipv6mr_interface = ifindex,
|
||||
};
|
||||
|
||||
ICMP6_FILTER_SETBLOCKALL(&filter);
|
||||
|
@ -17,8 +17,8 @@
|
||||
{ { { 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 } } }
|
||||
|
||||
int icmp6_bind_router_solicitation(int index);
|
||||
int icmp6_bind_router_advertisement(int index);
|
||||
int icmp6_bind_router_solicitation(int ifindex);
|
||||
int icmp6_bind_router_advertisement(int ifindex);
|
||||
int icmp6_send_router_solicitation(int s, const struct ether_addr *ether_addr);
|
||||
int icmp6_receive(int fd, void *buffer, size_t size, struct in6_addr *dst,
|
||||
triple_timestamp *timestamp);
|
||||
|
@ -159,7 +159,7 @@ int sd_dhcp6_client_set_callback(
|
||||
int sd_dhcp6_client_set_ifindex(sd_dhcp6_client *client, int ifindex) {
|
||||
|
||||
assert_return(client, -EINVAL);
|
||||
assert_return(ifindex >= -1, -EINVAL);
|
||||
assert_return(ifindex > 0, -EINVAL);
|
||||
assert_return(IN_SET(client->state, DHCP6_STATE_STOPPED), -EBUSY);
|
||||
|
||||
client->ifindex = ifindex;
|
||||
|
@ -415,7 +415,7 @@ _public_ int sd_radv_start(sd_radv *ra) {
|
||||
|
||||
_public_ int sd_radv_set_ifindex(sd_radv *ra, int ifindex) {
|
||||
assert_return(ra, -EINVAL);
|
||||
assert_return(ifindex >= -1, -EINVAL);
|
||||
assert_return(ifindex > 0, -EINVAL);
|
||||
|
||||
if (ra->state != SD_RADV_STATE_IDLE)
|
||||
return -EBUSY;
|
||||
|
@ -258,7 +258,7 @@ int dhcp_network_send_raw_socket(int s, const union sockaddr_union *link, const
|
||||
}
|
||||
|
||||
int dhcp_network_bind_raw_socket(
|
||||
int index,
|
||||
int ifindex,
|
||||
union sockaddr_union *link,
|
||||
uint32_t id,
|
||||
const uint8_t *addr, size_t addr_len,
|
||||
|
@ -30,7 +30,7 @@ static struct ether_addr mac_addr = {
|
||||
|
||||
static sd_event_source *hangcheck;
|
||||
static int test_dhcp_fd[2];
|
||||
static int test_index = 42;
|
||||
static int test_ifindex = 42;
|
||||
static int test_client_message_num;
|
||||
static be32_t test_iaid = 0;
|
||||
static uint8_t test_duid[14] = { };
|
||||
@ -48,7 +48,7 @@ static int test_client_basic(sd_event *e) {
|
||||
|
||||
assert_se(sd_dhcp6_client_set_ifindex(client, 15) == 0);
|
||||
assert_se(sd_dhcp6_client_set_ifindex(client, -42) == -EINVAL);
|
||||
assert_se(sd_dhcp6_client_set_ifindex(client, -1) == 0);
|
||||
assert_se(sd_dhcp6_client_set_ifindex(client, -1) == -EINVAL);
|
||||
assert_se(sd_dhcp6_client_set_ifindex(client, 42) >= 0);
|
||||
|
||||
assert_se(sd_dhcp6_client_set_mac(client, (const uint8_t *) &mac_addr,
|
||||
@ -877,8 +877,8 @@ int dhcp6_network_send_udp_socket(int s, struct in6_addr *server_address,
|
||||
return len;
|
||||
}
|
||||
|
||||
int dhcp6_network_bind_udp_socket(int index, struct in6_addr *local_address) {
|
||||
assert_se(index == test_index);
|
||||
int dhcp6_network_bind_udp_socket(int ifindex, struct in6_addr *local_address) {
|
||||
assert_se(ifindex == test_ifindex);
|
||||
|
||||
if (socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC | SOCK_NONBLOCK, 0, test_dhcp_fd) < 0)
|
||||
return -errno;
|
||||
@ -899,7 +899,7 @@ static int test_client_solicit(sd_event *e) {
|
||||
|
||||
assert_se(sd_dhcp6_client_attach_event(client, e, 0) >= 0);
|
||||
|
||||
assert_se(sd_dhcp6_client_set_ifindex(client, test_index) == 0);
|
||||
assert_se(sd_dhcp6_client_set_ifindex(client, test_ifindex) == 0);
|
||||
assert_se(sd_dhcp6_client_set_mac(client, (const uint8_t *) &mac_addr,
|
||||
sizeof (mac_addr),
|
||||
ARPHRD_ETHER) >= 0);
|
||||
|
@ -78,7 +78,7 @@ int arp_send_announcement(int fd, int ifindex,
|
||||
return arp_network_send_raw_socket(fd, ifindex, &ea);
|
||||
}
|
||||
|
||||
int arp_network_bind_raw_socket(int index, be32_t address, const struct ether_addr *eth_mac) {
|
||||
int arp_network_bind_raw_socket(int ifindex, be32_t address, const struct ether_addr *eth_mac) {
|
||||
if (socketpair(AF_UNIX, SOCK_DGRAM | SOCK_CLOEXEC | SOCK_NONBLOCK, 0, test_fd) < 0)
|
||||
return -errno;
|
||||
|
||||
|
@ -159,8 +159,8 @@ static void test_radv(void) {
|
||||
assert_se(ra);
|
||||
|
||||
assert_se(sd_radv_set_ifindex(NULL, 0) < 0);
|
||||
assert_se(sd_radv_set_ifindex(ra, 0) >= 0);
|
||||
assert_se(sd_radv_set_ifindex(ra, -1) >= 0);
|
||||
assert_se(sd_radv_set_ifindex(ra, 0) < 0);
|
||||
assert_se(sd_radv_set_ifindex(ra, -1) < 0);
|
||||
assert_se(sd_radv_set_ifindex(ra, -2) < 0);
|
||||
assert_se(sd_radv_set_ifindex(ra, 42) >= 0);
|
||||
|
||||
@ -219,12 +219,12 @@ static void test_radv(void) {
|
||||
assert_se(!ra);
|
||||
}
|
||||
|
||||
int icmp6_bind_router_solicitation(int index) {
|
||||
int icmp6_bind_router_solicitation(int ifindex) {
|
||||
return -ENOSYS;
|
||||
}
|
||||
|
||||
int icmp6_bind_router_advertisement(int index) {
|
||||
assert_se(index == 42);
|
||||
int icmp6_bind_router_advertisement(int ifindex) {
|
||||
assert_se(ifindex == 42);
|
||||
|
||||
return test_fd[1];
|
||||
}
|
||||
|
@ -174,8 +174,8 @@ static int test_rs_hangcheck(sd_event_source *s, uint64_t usec,
|
||||
return 0;
|
||||
}
|
||||
|
||||
int icmp6_bind_router_solicitation(int index) {
|
||||
assert_se(index == 42);
|
||||
int icmp6_bind_router_solicitation(int ifindex) {
|
||||
assert_se(ifindex == 42);
|
||||
|
||||
if (socketpair(AF_UNIX, SOCK_DGRAM | SOCK_CLOEXEC | SOCK_NONBLOCK, 0, test_fd) < 0)
|
||||
return -errno;
|
||||
@ -183,8 +183,7 @@ int icmp6_bind_router_solicitation(int index) {
|
||||
return test_fd[0];
|
||||
}
|
||||
|
||||
int icmp6_bind_router_advertisement(int index) {
|
||||
|
||||
int icmp6_bind_router_advertisement(int ifindex) {
|
||||
return -ENOSYS;
|
||||
}
|
||||
|
||||
|
@ -190,7 +190,7 @@ static int dns_stream_identify(DnsStream *s) {
|
||||
s->ifindex = manager_find_ifindex(s->manager, s->local.sa.sa_family, s->local.sa.sa_family == AF_INET ? (union in_addr_union*) &s->local.in.sin_addr : (union in_addr_union*) &s->local.in6.sin6_addr);
|
||||
|
||||
if (s->protocol == DNS_PROTOCOL_LLMNR && s->ifindex > 0) {
|
||||
uint32_t ifindex = htobe32(s->ifindex);
|
||||
be32_t ifindex = htobe32(s->ifindex);
|
||||
|
||||
/* Make sure all packets for this connection are sent on the same interface */
|
||||
if (s->local.sa.sa_family == AF_INET) {
|
||||
|
Loading…
Reference in New Issue
Block a user