public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
blob 9f2d39ccc0014a370494c893eee780c358b9307d 1801 bytes (raw)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
 
/* SPDX-License-Identifier: GPL-2.0-or-later
 * Copyright Red Hat
 * Author: David Gibson <david@gibson.dropbear.id.au>
 *
 * Passt/pasta interface types and IDs
 */

#include <stdint.h>
#include <assert.h>
#include <netinet/in.h>

#include "util.h"
#include "pif.h"
#include "siphash.h"
#include "ip.h"
#include "inany.h"
#include "passt.h"

const char *pif_type_str[] = {
	[PIF_NONE]		= "<none>",
	[PIF_HOST]		= "HOST",
	[PIF_TAP]		= "TAP",
	[PIF_SPLICE]		= "SPLICE",
};
static_assert(ARRAY_SIZE(pif_type_str) == PIF_NUM_TYPES,
	      "pif_type_str[] doesn't match enum pif_type");


/** pif_sockaddr() - Construct a socket address suitable for an interface
 * @c:		Execution context
 * @sa:		Pointer to sockaddr to fill in
 * @sl:		Updated to relevant of length of initialised @sa
 * @pif:	Interface to create the socket address
 * @addr:	IPv[46] address
 * @port:	Port (host byte order)
 *
 * Return: true if resulting socket address is non-trivial (specified address or
 *         non-zero port), false otherwise
 */
bool pif_sockaddr(const struct ctx *c, union sockaddr_inany *sa, socklen_t *sl,
		  uint8_t pif, const union inany_addr *addr, in_port_t port)
{
	const struct in_addr *v4 = inany_v4(addr);

	ASSERT(pif_is_socket(pif));

	if (v4) {
		sa->sa_family = AF_INET;
		sa->sa4.sin_addr = *v4;
		sa->sa4.sin_port = htons(port);
		memset(&sa->sa4.sin_zero, 0, sizeof(sa->sa4.sin_zero));
		*sl = sizeof(sa->sa4);
		return !IN4_IS_ADDR_UNSPECIFIED(v4) || port;
	}

	sa->sa_family = AF_INET6;
	sa->sa6.sin6_addr = addr->a6;
	sa->sa6.sin6_port = htons(port);
	if (pif == PIF_HOST && IN6_IS_ADDR_LINKLOCAL(&addr->a6))
		sa->sa6.sin6_scope_id = c->ifi6;
	else
		sa->sa6.sin6_scope_id = 0;
	sa->sa6.sin6_flowinfo = 0;
	*sl = sizeof(sa->sa6);
	return !IN6_IS_ADDR_UNSPECIFIED(&addr->a6) || port;
}

debug log:

solving 9f2d39cc ...
found 9f2d39cc in https://archives.passt.top/passt-dev/20240705020724.3447719-3-david@gibson.dropbear.id.au/
found ebf01cc8 in https://passt.top/passt
preparing index
index prepared:
100644 ebf01cc813af645b35d1b92e24a626091303b2ef	pif.c

applying [1/1] https://archives.passt.top/passt-dev/20240705020724.3447719-3-david@gibson.dropbear.id.au/
diff --git a/pif.c b/pif.c
index ebf01cc8..9f2d39cc 100644

Checking patch pif.c...
Applied patch pif.c cleanly.

index at:
100644 9f2d39ccc0014a370494c893eee780c358b9307d	pif.c

Code repositories for project(s) associated with this public inbox

	https://passt.top/passt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for IMAP folder(s).