14#ifndef ZEPHYR_INCLUDE_NET_PKT_FILTER_H_
15#define ZEPHYR_INCLUDE_NET_PKT_FILTER_H_
111#define npf_insert_send_rule(rule) npf_insert_rule(&npf_send_rules, rule)
112#define npf_insert_recv_rule(rule) npf_insert_rule(&npf_recv_rules, rule)
113#define npf_append_send_rule(rule) npf_append_rule(&npf_send_rules, rule)
114#define npf_append_recv_rule(rule) npf_append_rule(&npf_recv_rules, rule)
115#define npf_remove_send_rule(rule) npf_remove_rule(&npf_send_rules, rule)
116#define npf_remove_recv_rule(rule) npf_remove_rule(&npf_recv_rules, rule)
117#define npf_remove_all_send_rules() npf_remove_all_rules(&npf_send_rules)
118#define npf_remove_all_recv_rules() npf_remove_all_rules(&npf_recv_rules)
120#ifdef CONFIG_NET_PKT_FILTER_LOCAL_IN_HOOK
121#define npf_insert_local_in_recv_rule(rule) npf_insert_rule(&npf_local_in_recv_rules, rule)
122#define npf_append_local_in_recv_rule(rule) npf_append_rule(&npf_local_in_recv_rules, rule)
123#define npf_remove_local_in_recv_rule(rule) npf_remove_rule(&npf_local_in_recv_rules, rule)
124#define npf_remove_all_local_in_recv_rules() npf_remove_all_rules(&npf_local_in_recv_rules)
127#ifdef CONFIG_NET_PKT_FILTER_IPV4_HOOK
128#define npf_insert_ipv4_recv_rule(rule) npf_insert_rule(&npf_ipv4_recv_rules, rule)
129#define npf_append_ipv4_recv_rule(rule) npf_append_rule(&npf_ipv4_recv_rules, rule)
130#define npf_remove_ipv4_recv_rule(rule) npf_remove_rule(&npf_ipv4_recv_rules, rule)
131#define npf_remove_all_ipv4_recv_rules() npf_remove_all_rules(&npf_ipv4_recv_rules)
134#ifdef CONFIG_NET_PKT_FILTER_IPV6_HOOK
135#define npf_insert_ipv6_recv_rule(rule) npf_insert_rule(&npf_ipv6_recv_rules, rule)
136#define npf_append_ipv6_recv_rule(rule) npf_append_rule(&npf_ipv6_recv_rules, rule)
137#define npf_remove_ipv6_recv_rule(rule) npf_remove_rule(&npf_ipv6_recv_rules, rule)
138#define npf_remove_all_ipv6_recv_rules() npf_remove_all_rules(&npf_ipv6_recv_rules)
195#define NPF_RULE(_name, _result, ...) \
196 struct npf_rule _name = { \
197 .result = (_result), \
198 .nb_tests = NUM_VA_ARGS_LESS_1(__VA_ARGS__) + 1, \
199 .tests = { FOR_EACH(Z_NPF_TEST_ADDR, (,), __VA_ARGS__) }, \
202#define Z_NPF_TEST_ADDR(arg) &arg.test
214struct npf_test_iface {
219extern npf_test_fn_t npf_iface_match;
220extern npf_test_fn_t npf_iface_unmatch;
221extern npf_test_fn_t npf_orig_iface_match;
222extern npf_test_fn_t npf_orig_iface_unmatch;
232#define NPF_IFACE_MATCH(_name, _iface) \
233 struct npf_test_iface _name = { \
235 .test.fn = npf_iface_match, \
244#define NPF_IFACE_UNMATCH(_name, _iface) \
245 struct npf_test_iface _name = { \
247 .test.fn = npf_iface_unmatch, \
256#define NPF_ORIG_IFACE_MATCH(_name, _iface) \
257 struct npf_test_iface _name = { \
259 .test.fn = npf_orig_iface_match, \
268#define NPF_ORIG_IFACE_UNMATCH(_name, _iface) \
269 struct npf_test_iface _name = { \
271 .test.fn = npf_orig_iface_unmatch, \
276struct npf_test_size_bounds {
282extern npf_test_fn_t npf_size_inbounds;
292#define NPF_SIZE_MIN(_name, _size) \
293 struct npf_test_size_bounds _name = { \
296 .test.fn = npf_size_inbounds, \
305#define NPF_SIZE_MAX(_name, _size) \
306 struct npf_test_size_bounds _name = { \
309 .test.fn = npf_size_inbounds, \
319#define NPF_SIZE_BOUNDS(_name, _min_size, _max_size) \
320 struct npf_test_size_bounds _name = { \
321 .min = (_min_size), \
322 .max = (_max_size), \
323 .test.fn = npf_size_inbounds, \
335extern npf_test_fn_t npf_ip_src_addr_match;
336extern npf_test_fn_t npf_ip_src_addr_unmatch;
352#define NPF_IP_SRC_ADDR_ALLOWLIST(_name, _ip_addr_array, _ip_addr_num, _af) \
353 struct npf_test_ip _name = { \
354 .addr_family = _af, \
355 .ipaddr = (_ip_addr_array), \
356 .ipaddr_num = _ip_addr_num, \
357 .test.fn = npf_ip_src_addr_match, \
372#define NPF_IP_SRC_ADDR_BLOCKLIST(_name, _ip_addr_array, _ip_addr_num, _af) \
373 struct npf_test_ip _name = { \
374 .addr_family = _af, \
375 .ipaddr = (_ip_addr_array), \
376 .ipaddr_num = _ip_addr_num, \
377 .test.fn = npf_ip_src_addr_unmatch, \
390struct npf_test_eth_addr {
392 unsigned int nb_addresses;
393 struct net_eth_addr *addresses;
394 struct net_eth_addr mask;
397extern npf_test_fn_t npf_eth_src_addr_match;
398extern npf_test_fn_t npf_eth_src_addr_unmatch;
399extern npf_test_fn_t npf_eth_dst_addr_match;
400extern npf_test_fn_t npf_eth_dst_addr_unmatch;
413#define NPF_ETH_SRC_ADDR_MATCH(_name, _addr_array) \
414 struct npf_test_eth_addr _name = { \
415 .addresses = (_addr_array), \
416 .nb_addresses = ARRAY_SIZE(_addr_array), \
417 .test.fn = npf_eth_src_addr_match, \
418 .mask.addr = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }, \
430#define NPF_ETH_SRC_ADDR_UNMATCH(_name, _addr_array) \
431 struct npf_test_eth_addr _name = { \
432 .addresses = (_addr_array), \
433 .nb_addresses = ARRAY_SIZE(_addr_array), \
434 .test.fn = npf_eth_src_addr_unmatch, \
435 .mask.addr = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }, \
447#define NPF_ETH_DST_ADDR_MATCH(_name, _addr_array) \
448 struct npf_test_eth_addr _name = { \
449 .addresses = (_addr_array), \
450 .nb_addresses = ARRAY_SIZE(_addr_array), \
451 .test.fn = npf_eth_dst_addr_match, \
452 .mask.addr = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }, \
464#define NPF_ETH_DST_ADDR_UNMATCH(_name, _addr_array) \
465 struct npf_test_eth_addr _name = { \
466 .addresses = (_addr_array), \
467 .nb_addresses = ARRAY_SIZE(_addr_array), \
468 .test.fn = npf_eth_dst_addr_unmatch, \
469 .mask.addr = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }, \
482#define NPF_ETH_SRC_ADDR_MASK_MATCH(_name, _addr_array, ...) \
483 struct npf_test_eth_addr _name = { \
484 .addresses = (_addr_array), \
485 .nb_addresses = ARRAY_SIZE(_addr_array), \
486 .mask.addr = { __VA_ARGS__ }, \
487 .test.fn = npf_eth_src_addr_match, \
500#define NPF_ETH_DST_ADDR_MASK_MATCH(_name, _addr_array, ...) \
501 struct npf_test_eth_addr _name = { \
502 .addresses = (_addr_array), \
503 .nb_addresses = ARRAY_SIZE(_addr_array), \
504 .mask.addr = { __VA_ARGS__ }, \
505 .test.fn = npf_eth_dst_addr_match, \
510struct npf_test_eth_type {
515extern npf_test_fn_t npf_eth_type_match;
516extern npf_test_fn_t npf_eth_type_unmatch;
526#define NPF_ETH_TYPE_MATCH(_name, _type) \
527 struct npf_test_eth_type _name = { \
528 .type = htons(_type), \
529 .test.fn = npf_eth_type_match, \
538#define NPF_ETH_TYPE_UNMATCH(_name, _type) \
539 struct npf_test_eth_type _name = { \
540 .type = htons(_type), \
541 .test.fn = npf_eth_type_unmatch, \
net_verdict
Net Verdict.
Definition: net_core.h:98
void npf_insert_rule(struct npf_rule_list *rules, struct npf_rule *rule)
Insert a rule at the front of given rule list.
bool npf_remove_rule(struct npf_rule_list *rules, struct npf_rule *rule)
Remove a rule from the given rule list.
bool npf_remove_all_rules(struct npf_rule_list *rules)
Remove all rules from the given rule list.
struct npf_rule_list npf_local_in_recv_rules
rule list applied for local incoming packets
struct npf_rule_list npf_send_rules
rule list applied to outgoing packets
struct npf_rule npf_default_drop
Default rule list termination for rejecting a packet.
struct npf_rule_list npf_recv_rules
rule list applied to incoming packets
struct npf_rule npf_default_ok
Default rule list termination for accepting a packet.
struct npf_rule_list npf_ipv6_recv_rules
rule list applied for IPv6 incoming packets
struct npf_rule_list npf_ipv4_recv_rules
rule list applied for IPv4 incoming packets
void npf_append_rule(struct npf_rule_list *rules, struct npf_rule *rule)
Append a rule at the end of given rule list.
struct _slist sys_slist_t
Single-linked list structure.
Definition: slist.h:49
struct _snode sys_snode_t
Single-linked list node structure.
Definition: slist.h:39
Network core definitions.
#define bool
Definition: stdbool.h:13
__UINT32_TYPE__ uint32_t
Definition: stdint.h:90
__UINT8_TYPE__ uint8_t
Definition: stdint.h:88
__UINT16_TYPE__ uint16_t
Definition: stdint.h:89
Kernel Spin Lock.
Definition: spinlock.h:45
Network Interface structure.
Definition: net_if.h:615
Network packet.
Definition: net_pkt.h:63
rule set for a given test location
Definition: net_pkt_filter.h:61
sys_slist_t rule_head
Definition: net_pkt_filter.h:62
struct k_spinlock lock
Definition: net_pkt_filter.h:63
filter rule structure
Definition: net_pkt_filter.h:48
uint32_t nb_tests
number of tests for this rule
Definition: net_pkt_filter.h:51
struct npf_test * tests[]
pointers to npf_test instances
Definition: net_pkt_filter.h:52
enum net_verdict result
result if all tests pass
Definition: net_pkt_filter.h:50
sys_snode_t node
Definition: net_pkt_filter.h:49
common filter test structure to be embedded into larger structures
Definition: net_pkt_filter.h:43
npf_test_fn_t * fn
packet condition test function
Definition: net_pkt_filter.h:44