treewide: Use sa_family_t for address family variables

Sometimes we use sa_family_t for variables and parameters containing a
socket address family, other times we use a plain int.  Since sa_family_t
is what's actually used in struct sockaddr and friends, standardise on
that.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
This commit is contained in:
David Gibson 2024-02-19 18:56:46 +11:00 committed by Stefano Brivio
parent 1e6f92b995
commit 4e08d9b9c6
11 changed files with 20 additions and 19 deletions

6
icmp.c
View file

@ -62,7 +62,7 @@ static struct icmp_id_sock icmp_id_map[IP_VERSIONS][ICMP_NUM_IDS];
* @af: Address family (AF_INET or AF_INET6)
* @ref: epoll reference
*/
void icmp_sock_handler(const struct ctx *c, int af, union epoll_ref ref)
void icmp_sock_handler(const struct ctx *c, sa_family_t af, union epoll_ref ref)
{
struct icmp_id_sock *const id_sock = af == AF_INET
? &icmp_id_map[V4][ref.icmp.id] : &icmp_id_map[V6][ref.icmp.id];
@ -156,7 +156,7 @@ static void icmp_ping_close(const struct ctx *c, struct icmp_id_sock *id_sock)
* Return: Newly opened ping socket fd, or -1 on failure
*/
static int icmp_ping_new(const struct ctx *c, struct icmp_id_sock *id_sock,
int af, uint16_t id)
sa_family_t af, uint16_t id)
{
uint8_t proto = af == AF_INET ? IPPROTO_ICMP : IPPROTO_ICMPV6;
const char *const pname = af == AF_INET ? "ICMP" : "ICMPv6";
@ -209,7 +209,7 @@ cancel:
*
* Return: count of consumed packets (always 1, even if malformed)
*/
int icmp_tap_handler(const struct ctx *c, uint8_t pif, int af,
int icmp_tap_handler(const struct ctx *c, uint8_t pif, sa_family_t af,
const void *saddr, const void *daddr,
const struct pool *p, const struct timespec *now)
{

4
icmp.h
View file

@ -10,8 +10,8 @@
struct ctx;
void icmp_sock_handler(const struct ctx *c, int af, union epoll_ref ref);
int icmp_tap_handler(const struct ctx *c, uint8_t pif, int af,
void icmp_sock_handler(const struct ctx *c, sa_family_t af, union epoll_ref ref);
int icmp_tap_handler(const struct ctx *c, uint8_t pif, sa_family_t af,
const void *saddr, const void *daddr,
const struct pool *p, const struct timespec *now);
void icmp_timer(const struct ctx *c, const struct timespec *now);

View file

@ -60,7 +60,8 @@ static inline bool inany_equals(const union inany_addr *a,
* @af: Address family of @addr
* @addr: struct in_addr (IPv4) or struct in6_addr (IPv6)
*/
static inline void inany_from_af(union inany_addr *aa, int af, const void *addr)
static inline void inany_from_af(union inany_addr *aa,
sa_family_t af, const void *addr)
{
if (af == AF_INET6) {
aa->a6 = *((struct in6_addr *)addr);

12
tcp.c
View file

@ -1262,7 +1262,7 @@ static void tcp_hash_remove(const struct ctx *c,
* Return: connection pointer, if found, -ENOENT otherwise
*/
static struct tcp_tap_conn *tcp_hash_lookup(const struct ctx *c,
int af, const void *faddr,
sa_family_t af, const void *faddr,
in_port_t eport, in_port_t fport)
{
union inany_addr aany;
@ -1904,8 +1904,8 @@ static void tcp_bind_outbound(const struct ctx *c, int s, sa_family_t af)
* @optlen: Bytes in options: caller MUST ensure available length
* @now: Current timestamp
*/
static void tcp_conn_from_tap(struct ctx *c,
int af, const void *saddr, const void *daddr,
static void tcp_conn_from_tap(struct ctx *c, sa_family_t af,
const void *saddr, const void *daddr,
const struct tcphdr *th, const char *opts,
size_t optlen, const struct timespec *now)
{
@ -2479,7 +2479,7 @@ static void tcp_conn_from_sock_finish(struct ctx *c, struct tcp_tap_conn *conn,
*
* Return: count of consumed packets
*/
int tcp_tap_handler(struct ctx *c, uint8_t pif, int af,
int tcp_tap_handler(struct ctx *c, uint8_t pif, sa_family_t af,
const void *saddr, const void *daddr,
const struct pool *p, int idx, const struct timespec *now)
{
@ -2856,7 +2856,7 @@ void tcp_sock_handler(struct ctx *c, union epoll_ref ref, uint32_t events)
*
* Return: fd for the new listening socket, negative error code on failure
*/
static int tcp_sock_init_af(const struct ctx *c, int af, in_port_t port,
static int tcp_sock_init_af(const struct ctx *c, sa_family_t af, in_port_t port,
const void *addr, const char *ifname)
{
union tcp_listen_epoll_ref tref = {
@ -3008,7 +3008,7 @@ static int tcp_ns_socks_init(void *arg)
* @pool: Pool of sockets to refill
* @af: Address family to use
*/
void tcp_sock_refill_pool(const struct ctx *c, int pool[], int af)
void tcp_sock_refill_pool(const struct ctx *c, int pool[], sa_family_t af)
{
int i;

2
tcp.h
View file

@ -14,7 +14,7 @@ void tcp_timer_handler(struct ctx *c, union epoll_ref ref);
void tcp_listen_handler(struct ctx *c, union epoll_ref ref,
const struct timespec *now);
void tcp_sock_handler(struct ctx *c, union epoll_ref ref, uint32_t events);
int tcp_tap_handler(struct ctx *c, uint8_t pif, int af,
int tcp_tap_handler(struct ctx *c, uint8_t pif, sa_family_t af,
const void *saddr, const void *daddr,
const struct pool *p, int idx, const struct timespec *now);
int tcp_sock_init(const struct ctx *c, sa_family_t af, const void *addr,

View file

@ -160,7 +160,7 @@ bool tcp_splice_flow_defer(union flow *flow);
void tcp_splice_timer(const struct ctx *c, union flow *flow);
int tcp_conn_pool_sock(int pool[]);
int tcp_conn_new_sock(const struct ctx *c, sa_family_t af);
void tcp_sock_refill_pool(const struct ctx *c, int pool[], int af);
void tcp_sock_refill_pool(const struct ctx *c, int pool[], sa_family_t af);
void tcp_splice_refill(const struct ctx *c);
#endif /* TCP_CONN_H */

View file

@ -399,7 +399,7 @@ static int tcp_splice_new(const struct ctx *c, struct tcp_splice_conn *conn,
*/
if (pif == PIF_SPLICE) {
int *p = CONN_V6(conn) ? init_sock_pool6 : init_sock_pool4;
int af = CONN_V6(conn) ? AF_INET6 : AF_INET;
sa_family_t af = CONN_V6(conn) ? AF_INET6 : AF_INET;
s = tcp_conn_pool_sock(p);
if (s < 0)

2
udp.c
View file

@ -816,7 +816,7 @@ void udp_sock_handler(const struct ctx *c, union epoll_ref ref, uint32_t events,
* #syscalls sendmmsg
*/
int udp_tap_handler(struct ctx *c, uint8_t pif,
int af, const void *saddr, const void *daddr,
sa_family_t af, const void *saddr, const void *daddr,
const struct pool *p, int idx, const struct timespec *now)
{
struct mmsghdr mm[UIO_MAXIOV];

2
udp.h
View file

@ -11,7 +11,7 @@
void udp_portmap_clear(void);
void udp_sock_handler(const struct ctx *c, union epoll_ref ref, uint32_t events,
const struct timespec *now);
int udp_tap_handler(struct ctx *c, uint8_t pif, int af,
int udp_tap_handler(struct ctx *c, uint8_t pif, sa_family_t af,
const void *saddr, const void *daddr,
const struct pool *p, int idx, const struct timespec *now);
int udp_sock_init(const struct ctx *c, int ns, sa_family_t af,

2
util.c
View file

@ -97,7 +97,7 @@ found:
*
* Return: newly created socket, negative error code on failure
*/
int sock_l4(const struct ctx *c, int af, uint8_t proto,
int sock_l4(const struct ctx *c, sa_family_t af, uint8_t proto,
const void *bind_addr, const char *ifname, uint16_t port,
uint32_t data)
{

2
util.h
View file

@ -212,7 +212,7 @@ struct ipv6_opt_hdr {
__attribute__ ((weak)) int ffsl(long int i) { return __builtin_ffsl(i); }
char *ipv6_l4hdr(const struct pool *p, int idx, size_t offset, uint8_t *proto,
size_t *dlen);
int sock_l4(const struct ctx *c, int af, uint8_t proto,
int sock_l4(const struct ctx *c, sa_family_t af, uint8_t proto,
const void *bind_addr, const char *ifname, uint16_t port,
uint32_t data);
void sock_probe_mem(struct ctx *c);