mirror of
https://passt.top/passt
synced 2025-05-21 00:35:34 +02:00
util, pif: Replace sock_l4() with pif_sock_l4()
The sock_l4() function is very convenient for creating sockets bound to a given address, but its interface has some problems. Most importantly, the address and port alone aren't enough in some cases. For link-local addresses (at least) we also need the pif in order to properly construct a socket adddress. This case doesn't yet arise, but it might cause us trouble in future. Additionally, sock_l4() can take AF_UNSPEC with the special meaning that it should attempt to create a "dual stack" socket which will respond to both IPv4 and IPv6 traffic. This only makes sense if there is no specific address given. We verify this at runtime, but it would be nicer if we could enforce it structurally. For sockets associated specifically with a single flow we already replaced sock_l4() with flowside_sock_l4() which avoids those problems. Now, replace all the remaining users with a new pif_sock_l4() which also takes an explicit pif. The new function takes the address as an inany *, with NULL indicating the dual stack case. This does add some complexity in some of the callers, however future planned cleanups should make this go away again. Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
This commit is contained in:
parent
204e77cd11
commit
b8d4fac6a2
6 changed files with 84 additions and 72 deletions
3
util.h
3
util.h
|
@ -181,9 +181,6 @@ int close_range(unsigned int first, unsigned int last, int flags) {
|
|||
int sock_l4_sa(const struct ctx *c, enum epoll_type type,
|
||||
const void *sa, socklen_t sl,
|
||||
const char *ifname, bool v6only, uint32_t data);
|
||||
int sock_l4(const struct ctx *c, sa_family_t af, enum epoll_type type,
|
||||
const void *bind_addr, const char *ifname, uint16_t port,
|
||||
uint32_t data);
|
||||
void sock_probe_mem(struct ctx *c);
|
||||
long timespec_diff_ms(const struct timespec *a, const struct timespec *b);
|
||||
int64_t timespec_diff_us(const struct timespec *a, const struct timespec *b);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue