mirror of
https://passt.top/passt
synced 2025-06-18 13:05:35 +02:00
flow: Common address information for target side
Require the address and port information for the target (non initiating) side to be populated when a flow enters TGT state. Implement that for TCP and ICMP. For now this leaves some information redundantly recorded in both generic and type specific fields. We'll fix that in later patches. For TCP we now use the information from the flow to construct the destination socket address in both tcp_conn_from_tap() and tcp_splice_connect(). Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
This commit is contained in:
parent
8012f5ff55
commit
4e2d36e83f
8 changed files with 153 additions and 78 deletions
40
pif.c
40
pif.c
|
@ -7,9 +7,14 @@
|
|||
|
||||
#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>",
|
||||
|
@ -19,3 +24,38 @@ const char *pif_type_str[] = {
|
|||
};
|
||||
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 length of initialised @sa
|
||||
* @pif: Interface to create the socket address
|
||||
* @addr: IPv[46] address
|
||||
* @port: Port (host byte order)
|
||||
*/
|
||||
void 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);
|
||||
} else {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue