aboutgitcodebugslistschat
path: root/flow.h
diff options
context:
space:
mode:
Diffstat (limited to 'flow.h')
-rw-r--r--flow.h97
1 files changed, 78 insertions, 19 deletions
diff --git a/flow.h b/flow.h
index 078fd60..db02845 100644
--- a/flow.h
+++ b/flow.h
@@ -7,6 +7,12 @@
#ifndef FLOW_H
#define FLOW_H
+#include <stdint.h>
+#include <netinet/in.h>
+
+#include "inany.h"
+#include "util.h"
+
#define FLOW_TIMER_INTERVAL 1000 /* ms */
/**
@@ -99,7 +105,7 @@ static_assert(FLOW_NUM_STATES <= (1 << FLOW_STATE_BITS),
extern const char *flow_state_str[];
#define FLOW_STATE(f) \
- ((f)->state < FLOW_NUM_STATES ? flow_state_str[(f)->state] : "?")
+ ((f)->state < FLOW_NUM_STATES ? flow_state_str[(f)->state] : "?")
/**
* enum flow_type - Different types of packet flows we track
@@ -126,7 +132,7 @@ static_assert(FLOW_NUM_TYPES <= (1 << FLOW_TYPE_BITS),
extern const char *flow_type_str[];
#define FLOW_TYPE(f) \
- ((f)->type < FLOW_NUM_TYPES ? flow_type_str[(f)->type] : "?")
+ ((f)->type < FLOW_NUM_TYPES ? flow_type_str[(f)->type] : "?")
extern const uint8_t flow_proto[];
#define FLOW_PROTO(f) \
@@ -140,14 +146,14 @@ extern const uint8_t flow_proto[];
/**
* struct flowside - Address information for one side of a flow
* @eaddr: Endpoint address (remote address from passt's PoV)
- * @faddr: Forwarding address (local address from passt's PoV)
+ * @oaddr: Our address (local address from passt's PoV)
* @eport: Endpoint port
- * @fport: Forwarding port
+ * @oport: Our port
*/
struct flowside {
- union inany_addr faddr;
+ union inany_addr oaddr;
union inany_addr eaddr;
- in_port_t fport;
+ in_port_t oport;
in_port_t eport;
};
@@ -162,12 +168,12 @@ static inline bool flowside_eq(const struct flowside *left,
{
return inany_equals(&left->eaddr, &right->eaddr) &&
left->eport == right->eport &&
- inany_equals(&left->faddr, &right->faddr) &&
- left->fport == right->fport;
+ inany_equals(&left->oaddr, &right->oaddr) &&
+ left->oport == right->oport;
}
int flowside_sock_l4(const struct ctx *c, enum epoll_type type, uint8_t pif,
- const struct flowside *tgt, uint32_t data);
+ const struct flowside *side);
int flowside_connect(const struct ctx *c, int s,
uint8_t pif, const struct flowside *tgt);
@@ -177,6 +183,8 @@ int flowside_connect(const struct ctx *c, int s,
* @type: Type of packet flow
* @pif[]: Interface for each side of the flow
* @side[]: Information for each side of the flow
+ * @tap_omac: MAC address of remote endpoint as seen from the guest
+ * @epollid: epollfd identifier
*/
struct flow_common {
#ifdef __GNUC__
@@ -192,8 +200,16 @@ struct flow_common {
#endif
uint8_t pif[SIDES];
struct flowside side[SIDES];
+
+ uint8_t tap_omac[6];
+
+#define EPOLLFD_ID_BITS 8
+ unsigned int epollid:EPOLLFD_ID_BITS;
};
+#define EPOLLFD_ID_DEFAULT 0
+#define EPOLLFD_ID_SIZE (1 << EPOLLFD_ID_BITS)
+
#define FLOW_INDEX_BITS 17 /* 128k - 1 */
#define FLOW_MAX MAX_FROM_BITS(FLOW_INDEX_BITS)
@@ -240,28 +256,71 @@ uint64_t flow_hash_insert(const struct ctx *c, flow_sidx_t sidx);
void flow_hash_remove(const struct ctx *c, flow_sidx_t sidx);
flow_sidx_t flow_lookup_af(const struct ctx *c,
uint8_t proto, uint8_t pif, sa_family_t af,
- const void *eaddr, const void *faddr,
- in_port_t eport, in_port_t fport);
+ const void *eaddr, const void *oaddr,
+ in_port_t eport, in_port_t oport);
flow_sidx_t flow_lookup_sa(const struct ctx *c, uint8_t proto, uint8_t pif,
- const void *esa, in_port_t fport);
+ const void *esa,
+ const union inany_addr *oaddr, in_port_t oport);
union flow;
void flow_init(void);
+int flow_epollfd(const struct flow_common *f);
+void flow_epollid_set(struct flow_common *f, int epollid);
+int flow_epoll_set(const struct flow_common *f, int command, uint32_t events,
+ int fd, unsigned int sidei);
+void flow_epollid_register(int epollid, int epollfd);
void flow_defer_handler(const struct ctx *c, const struct timespec *now);
+int flow_migrate_source_early(struct ctx *c, const struct migrate_stage *stage,
+ int fd);
+int flow_migrate_source_pre(struct ctx *c, const struct migrate_stage *stage,
+ int fd, const struct timespec *now);
+int flow_migrate_source(struct ctx *c, const struct migrate_stage *stage,
+ int fd, const struct timespec *now);
+int flow_migrate_target(struct ctx *c, const struct migrate_stage *stage,
+ int fd, const struct timespec *now);
-void flow_log_(const struct flow_common *f, int pri, const char *fmt, ...)
- __attribute__((format(printf, 3, 4)));
+void flow_log__(const struct flow_common *f, int pri, bool perror, bool details,
+ enum flow_state state, const char *fmt, ...)
+ __attribute__((format(printf, 6, 7)));
-#define flow_log(f_, pri, ...) flow_log_(&(f_)->f, (pri), __VA_ARGS__)
+#define flow_log_(f_, pri_, perror_, ...) \
+ flow_log__((f_), (pri_), (perror_), (pri_) > LOG_DEBUG, \
+ (f_)->state, __VA_ARGS__)
-#define flow_dbg(f, ...) flow_log((f), LOG_DEBUG, __VA_ARGS__)
-#define flow_err(f, ...) flow_log((f), LOG_ERR, __VA_ARGS__)
+#define flow_log(flow_, pri_, perror_, ...) \
+ flow_log_(&(flow_)->f, (pri_), (perror_), __VA_ARGS__)
-#define flow_trace(f, ...) \
+#define flow_dbg(flow_, ...) \
+ flow_log((flow_), LOG_DEBUG, false, __VA_ARGS__)
+#define flow_warn(flow_, ...) \
+ flow_log((flow_), LOG_WARNING, false, __VA_ARGS__)
+#define flow_err(flow_, ...) \
+ flow_log((flow_), LOG_ERR, false, __VA_ARGS__)
+#define flow_trace(flow_, ...) \
do { \
if (log_trace) \
- flow_dbg((f), __VA_ARGS__); \
+ flow_dbg((flow_), __VA_ARGS__); \
} while (0)
+#define flow_dbg_perror(flow_, ...) \
+ flow_log((flow_), LOG_DEBUG, true, __VA_ARGS__)
+#define flow_warn_perror(flow_, ...) \
+ flow_log((flow_), LOG_WARNING, true, __VA_ARGS__)
+#define flow_perror(flow_, ...) \
+ flow_log((flow_), LOG_ERR, true, __VA_ARGS__)
+
+#define flow_dbg_ratelimit(flow_, now_, ...) \
+ logmsg_ratelimit(flow_dbg, debug, (now_), (flow_), __VA_ARGS__)
+#define flow_dbg_perror_ratelimit(flow_, now_, ...) \
+ logmsg_ratelimit(flow_dbg_perror, debug, (now_), (flow_), __VA_ARGS__)
+#define flow_warn_ratelimit(flow_, now_, ...) \
+ logmsg_ratelimit(flow_warn, warn, (now_), (flow_), __VA_ARGS__)
+#define flow_warn_perror_ratelimit(flow_, now_, ...) \
+ logmsg_ratelimit(flow_warn_perror, warn, (now_), (flow_), __VA_ARGS__)
+#define flow_err_ratelimit(flow_, now_, ...) \
+ logmsg_ratelimit(flow_err, err, (now_), (flow_), __VA_ARGS__)
+#define flow_perror_ratelimit(flow_, now_, ...) \
+ logmsg_ratelimit(flow_perror, err, (now_), (flow_), __VA_ARGS__)
+
#endif /* FLOW_H */