public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
blob da9483b3fe6eabe72fe5d71dd91c55b753f87ccf 4628 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
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
 
/* SPDX-License-Identifier: GPL-2.0-or-later
 * Copyright Red Hat
 * Author: David Gibson <david@gibson.dropbear.id.au>
 *
 * Definitions for the global table of packet flows.
 */
#ifndef FLOW_TABLE_H
#define FLOW_TABLE_H

#include "tcp_conn.h"
#include "icmp_flow.h"
#include "udp_flow.h"

/**
 * struct flow_free_cluster - Information about a cluster of free entries
 * @f:		Generic flow information
 * @n:		Number of entries in the free cluster (including this one)
 * @next:	Index of next free cluster
 */
struct flow_free_cluster {
	/* Must be first element */
	struct flow_common f;
	unsigned n;
	unsigned next;
};

/**
 * union flow - Descriptor for a logical packet flow (e.g. connection)
 * @f:		Fields common between all variants
 * @tcp:	Fields for non-spliced TCP connections
 * @tcp_splice:	Fields for spliced TCP connections
*/
union flow {
	struct flow_common f;
	struct flow_free_cluster free;
	struct tcp_tap_conn tcp;
	struct tcp_splice_conn tcp_splice;
	struct icmp_ping_flow ping;
	struct udp_flow udp;
};

/* Global Flow Table */
extern unsigned flow_first_free;
extern union flow flowtab[];


/** flow_idx - Index of flow from common structure
 * @f:	Common flow fields pointer
 *
 * Return: index of @f in the flow table
 */
static inline unsigned flow_idx(const struct flow_common *f)
{
	return (union flow *)f - flowtab;
}

/** FLOW_IDX - Find the index of a flow
 * @f_:	Flow pointer, either union flow * or protocol specific
 *
 * Return: index of @f in the flow table
 */
#define FLOW_IDX(f_)		(flow_idx(&(f_)->f))

/** FLOW - Flow entry at a given index
 * @idx:	Flow index
 *
 * Return: pointer to entry @idx in the flow table
 */
#define FLOW(idx)		(&flowtab[(idx)])

/** flow_at_sidx - Flow entry for a given sidx
 * @sidx:	Flow & side index
 *
 * Return: pointer to the corresponding flow entry, or NULL
 */
static inline union flow *flow_at_sidx(flow_sidx_t sidx)
{
	if (!flow_sidx_valid(sidx))
		return NULL;
	return FLOW(sidx.flow);
}

/** flow_sidx_opposite - Get the other side of the same flow
 * @sidx:	Flow & side index
 *
 * Return: sidx for the other side of the same flow as @sidx
 */
static inline flow_sidx_t flow_sidx_opposite(flow_sidx_t sidx)
{
	if (!flow_sidx_valid(sidx))
		return FLOW_SIDX_NONE;
	return (flow_sidx_t){.flow = sidx.flow, .side = !sidx.side};
}

/** pif_at_sidx - Interface for a given flow and side
 * @sidx:    Flow & side index
 *
 * Return: pif for the flow & side given by @sidx
 */
static inline uint8_t pif_at_sidx(flow_sidx_t sidx)
{
	const union flow *flow = flow_at_sidx(sidx);

	if (!flow)
		return PIF_NONE;
	return flow->f.pif[sidx.side];
}

/** flowside_at_sidx - Retrieve a specific flowside
 * @sidx:    Flow & side index
 *
 * Return: Flowside for the flow & side given by @sidx
 */
static inline const struct flowside *flowside_at_sidx(flow_sidx_t sidx)
{
	const union flow *flow = flow_at_sidx(sidx);

	if (!flow)
		return PIF_NONE;
	return &flow->f.side[sidx.side];
}

/** flow_sidx_t - Index of one side of a flow from common structure
 * @f:		Common flow fields pointer
 * @side:	Which side to refer to (0 or 1)
 *
 * Return: index of @f and @side in the flow table
 */
static inline flow_sidx_t flow_sidx(const struct flow_common *f,
				    int side)
{
	/* cppcheck-suppress [knownConditionTrueFalse, unmatchedSuppression] */
	ASSERT(side == !!side);

	return (flow_sidx_t){
		.side = side,
		.flow = flow_idx(f),
	};
}

/** FLOW_SIDX - Find the index of one side of a flow
 * @f_:		Flow pointer, either union flow * or protocol specific
 * @side:	Which side to index (0 or 1)
 *
 * Return: index of @f and @side in the flow table
 */
#define FLOW_SIDX(f_, side)	(flow_sidx(&(f_)->f, (side)))

union flow *flow_alloc(void);
void flow_alloc_cancel(union flow *flow);

const struct flowside *flow_initiate_af(union flow *flow, uint8_t pif,
					sa_family_t af,
					const void *saddr, in_port_t sport,
					const void *daddr, in_port_t dport);
const struct flowside *flow_initiate_sa(union flow *flow, uint8_t pif,
					const union sockaddr_inany *ssa,
					in_port_t dport);
const struct flowside *flow_target_af(union flow *flow, uint8_t pif,
				      sa_family_t af,
				      const void *saddr, in_port_t sport,
				      const void *daddr, in_port_t dport);
const struct flowside *flow_target(const struct ctx *c, union flow *flow,
				   uint8_t proto);

union flow *flow_set_type(union flow *flow, enum flow_type type);
#define FLOW_SET_TYPE(flow_, t_, var_)	(&flow_set_type((flow_), (t_))->var_)

void flow_activate(struct flow_common *f);
#define FLOW_ACTIVATE(flow_)			\
	(flow_activate(&(flow_)->f))

#endif /* FLOW_TABLE_H */

debug log:

solving da9483b3 ...
found da9483b3 in https://archives.passt.top/passt-dev/20240705020724.3447719-25-david@gibson.dropbear.id.au/
found 1faac4a7 in https://archives.passt.top/passt-dev/20240705020724.3447719-22-david@gibson.dropbear.id.au/
found 3fbc7c8d in https://archives.passt.top/passt-dev/20240705020724.3447719-21-david@gibson.dropbear.id.au/
found 457f27b1 in https://archives.passt.top/passt-dev/20240705020724.3447719-18-david@gibson.dropbear.id.au/
found 00dca4b2 in https://archives.passt.top/passt-dev/20240705020724.3447719-3-david@gibson.dropbear.id.au/ ||
	https://archives.passt.top/passt-dev/20240705020724.3447719-10-david@gibson.dropbear.id.au/
found ad1bc787 in https://archives.passt.top/passt-dev/20240705020724.3447719-2-david@gibson.dropbear.id.au/
found 226ddbdd in https://passt.top/passt
preparing index
index prepared:
100644 226ddbdd3fa3bd5903d7df0521d387a950b8e01c	flow_table.h

applying [1/6] https://archives.passt.top/passt-dev/20240705020724.3447719-2-david@gibson.dropbear.id.au/
diff --git a/flow_table.h b/flow_table.h
index 226ddbdd..ad1bc787 100644


applying [2/6] https://archives.passt.top/passt-dev/20240705020724.3447719-3-david@gibson.dropbear.id.au/
diff --git a/flow_table.h b/flow_table.h
index ad1bc787..00dca4b2 100644

Checking patch flow_table.h...
Applied patch flow_table.h cleanly.
Checking patch flow_table.h...
Applied patch flow_table.h cleanly.

skipping https://archives.passt.top/passt-dev/20240705020724.3447719-10-david@gibson.dropbear.id.au/ for 00dca4b2
index at:
100644 00dca4b2c0fc45380cea1046316221e576669a61	flow_table.h

applying [3/6] https://archives.passt.top/passt-dev/20240705020724.3447719-18-david@gibson.dropbear.id.au/
diff --git a/flow_table.h b/flow_table.h
index 00dca4b2..457f27b1 100644


applying [4/6] https://archives.passt.top/passt-dev/20240705020724.3447719-21-david@gibson.dropbear.id.au/
diff --git a/flow_table.h b/flow_table.h
index 457f27b1..3fbc7c8d 100644


applying [5/6] https://archives.passt.top/passt-dev/20240705020724.3447719-22-david@gibson.dropbear.id.au/
diff --git a/flow_table.h b/flow_table.h
index 3fbc7c8d..1faac4a7 100644


applying [6/6] https://archives.passt.top/passt-dev/20240705020724.3447719-25-david@gibson.dropbear.id.au/
diff --git a/flow_table.h b/flow_table.h
index 1faac4a7..da9483b3 100644

Checking patch flow_table.h...
Applied patch flow_table.h cleanly.
Checking patch flow_table.h...
Applied patch flow_table.h cleanly.
Checking patch flow_table.h...
Applied patch flow_table.h cleanly.
Checking patch flow_table.h...
Applied patch flow_table.h cleanly.

index at:
100644 da9483b3fe6eabe72fe5d71dd91c55b753f87ccf	flow_table.h

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).