/* SPDX-License-Identifier: GPL-2.0-or-later * Copyright Red Hat * Author: David Gibson * * Tracking for logical "flows" of packets. */ #ifndef FLOW_H #define FLOW_H /** * struct demiflow - Describes a logical packet flow as seen from one "side" * @caddr: Correspondent address (remote address from passt's PoV) * @faddr: Forwarding address (local address from passt's PoV) * @cport: Correspondent port * @fport: Forwarding port */ struct demiflow { union inany_addr faddr; union inany_addr caddr; in_port_t fport, cport; }; /** demiflow_from_af - Initialize a demiflow from addresses * @df: demiflow to initialize * @af: Address family for @faddr and @caddr * @faddr: Forwarding address (pointer to in_addr or in6_addr) * @fport: Forwarding port * @caddr: Correspondent address (pointer to in_addr or in6_addr) * @cport: Correspondent port */ static inline void demiflow_from_af(struct demiflow *df, int af, const void *faddr, in_port_t fport, const void *caddr, in_port_t cport) { inany_from_af(&df->faddr, af, faddr); inany_from_af(&df->caddr, af, caddr); df->fport = fport; df->cport = cport; } /** * demiflow_eq() - Check if two demiflows are equal * @left, @right: Demiflows to compare * * Return: true if equal, false otherwise */ static inline bool demiflow_eq(const struct demiflow *left, const struct demiflow *right) { return memcmp(left, right, sizeof(struct demiflow)) == 0; } /** * demiflow_hash() - Calculate hash value for a demiflow * @df: Demiflow * @k: Hash secret (128-bits as array of 2 64-bit words) * * Return: hash value */ static inline unsigned int demiflow_hash(const struct demiflow *df, const uint64_t *k) { return siphash_36b((uint8_t *)df, k); } #endif /* FLOW_H */