Annotation of fwsync/driver/fwsync_utils.c, revision 1.3
1.1 misho 1: /*************************************************************************
2: * (C) 2022 CloudSigma AG - Sofia/Bulgaria
3: * by Michael Pounov <misho@elwix.org>
4: **************************************************************************/
5: #include "fwsync.h"
6:
7:
1.3 ! misho 8: #if 0
1.2 misho 9: #ifndef IPFIREWALL_JENKINSHASH
10: __inline uint32_t
11: fwsync_hash_packet(const struct ipfw_flow_id *id)
12: {
13: uint32_t i;
14:
15: #ifdef INET6
16: if (IS_IP6_FLOW_ID(id))
17: i = ntohl((id->dst_ip6.__u6_addr.__u6_addr32[2]) ^
18: (id->dst_ip6.__u6_addr.__u6_addr32[3]) ^
19: (id->src_ip6.__u6_addr.__u6_addr32[2]) ^
20: (id->src_ip6.__u6_addr.__u6_addr32[3]));
21: else
22: #endif /* INET6 */
23: i = (id->dst_ip) ^ (id->src_ip);
24: i ^= (id->dst_port) ^ (id->src_port);
25: return (i);
26: }
27:
28: __inline uint32_t
29: fwsync_hash_parent(const struct ipfw_flow_id *id, const void *rule)
30: {
31:
32: return (fwsync_hash_packet(id) ^ ((uintptr_t)rule));
33: }
34:
35: #else /* IPFIREWALL_JENKINSHASH */
36:
37: VNET_DEFINE_STATIC(uint32_t, dyn_hashseed);
38: #define V_dyn_hashseed VNET(dyn_hashseed)
39:
40: static __inline int
41: addrcmp4(const struct ipfw_flow_id *id)
42: {
43:
44: if (id->src_ip < id->dst_ip)
45: return (0);
46: if (id->src_ip > id->dst_ip)
47: return (1);
48: if (id->src_port <= id->dst_port)
49: return (0);
50: return (1);
51: }
52:
53: #ifdef INET6
54: static __inline int
55: addrcmp6(const struct ipfw_flow_id *id)
56: {
57: int ret;
58:
59: ret = memcmp(&id->src_ip6, &id->dst_ip6, sizeof(struct in6_addr));
60: if (ret < 0)
61: return (0);
62: if (ret > 0)
63: return (1);
64: if (id->src_port <= id->dst_port)
65: return (0);
66: return (1);
67: }
68:
69: __inline uint32_t
70: fwsync_hash_packet6(const struct ipfw_flow_id *id)
71: {
72: struct tuple6 {
73: struct in6_addr addr[2];
74: uint16_t port[2];
75: } t6;
76:
77: if (addrcmp6(id) == 0) {
78: t6.addr[0] = id->src_ip6;
79: t6.addr[1] = id->dst_ip6;
80: t6.port[0] = id->src_port;
81: t6.port[1] = id->dst_port;
82: } else {
83: t6.addr[0] = id->dst_ip6;
84: t6.addr[1] = id->src_ip6;
85: t6.port[0] = id->dst_port;
86: t6.port[1] = id->src_port;
87: }
88: return (jenkins_hash32((const uint32_t *)&t6,
89: sizeof(t6) / sizeof(uint32_t), V_dyn_hashseed));
90: }
91: #endif
92:
93: __inline uint32_t
94: fwsync_hash_packet(const struct ipfw_flow_id *id)
95: {
96: struct tuple4 {
97: in_addr_t addr[2];
98: uint16_t port[2];
99: } t4;
100:
101: if (IS_IP4_FLOW_ID(id)) {
102: /* All fields are in host byte order */
103: if (addrcmp4(id) == 0) {
104: t4.addr[0] = id->src_ip;
105: t4.addr[1] = id->dst_ip;
106: t4.port[0] = id->src_port;
107: t4.port[1] = id->dst_port;
108: } else {
109: t4.addr[0] = id->dst_ip;
110: t4.addr[1] = id->src_ip;
111: t4.port[0] = id->dst_port;
112: t4.port[1] = id->src_port;
113: }
114: return (jenkins_hash32((const uint32_t *)&t4,
115: sizeof(t4) / sizeof(uint32_t), V_dyn_hashseed));
116: } else
117: #ifdef INET6
118: if (IS_IP6_FLOW_ID(id))
119: return (fwsync_hash_packet6(id));
120: #endif
121: return (0);
122: }
123:
124: __inline uint32_t
125: fwsync_hash_parent(const struct ipfw_flow_id *id, const void *rule)
126: {
127:
128: return (jenkins_hash32((const uint32_t *)&rule,
129: sizeof(rule) / sizeof(uint32_t), fwsync_hash_packet(id)));
130: }
131: #endif /* IPFIREWALL_JENKINSHASH */
1.3 ! misho 132: #endif
! 133:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>