14#ifndef ZEPHYR_INCLUDE_NET_PKT_FILTER_H_
15#define ZEPHYR_INCLUDE_NET_PKT_FILTER_H_
105#define npf_insert_send_rule(rule) npf_insert_rule(&npf_send_rules, rule)
106#define npf_insert_recv_rule(rule) npf_insert_rule(&npf_recv_rules, rule)
107#define npf_append_send_rule(rule) npf_append_rule(&npf_send_rules, rule)
108#define npf_append_recv_rule(rule) npf_append_rule(&npf_recv_rules, rule)
109#define npf_remove_send_rule(rule) npf_remove_rule(&npf_send_rules, rule)
110#define npf_remove_recv_rule(rule) npf_remove_rule(&npf_recv_rules, rule)
111#define npf_remove_all_send_rules() npf_remove_all_rules(&npf_send_rules)
112#define npf_remove_all_recv_rules() npf_remove_all_rules(&npf_recv_rules)
168#define NPF_RULE(_name, _result, ...) \
169 struct npf_rule _name = { \
170 .result = (_result), \
171 .nb_tests = NUM_VA_ARGS_LESS_1(__VA_ARGS__) + 1, \
172 .tests = { FOR_EACH(Z_NPF_TEST_ADDR, (,), __VA_ARGS__) }, \
175#define Z_NPF_TEST_ADDR(arg) &arg.test
187struct npf_test_iface {
192extern npf_test_fn_t npf_iface_match;
193extern npf_test_fn_t npf_iface_unmatch;
194extern npf_test_fn_t npf_orig_iface_match;
195extern npf_test_fn_t npf_orig_iface_unmatch;
205#define NPF_IFACE_MATCH(_name, _iface) \
206 struct npf_test_iface _name = { \
208 .test.fn = npf_iface_match, \
217#define NPF_IFACE_UNMATCH(_name, _iface) \
218 struct npf_test_iface _name = { \
220 .test.fn = npf_iface_unmatch, \
229#define NPF_ORIG_IFACE_MATCH(_name, _iface) \
230 struct npf_test_iface _name = { \
232 .test.fn = npf_orig_iface_match, \
241#define NPF_ORIG_IFACE_UNMATCH(_name, _iface) \
242 struct npf_test_iface _name = { \
244 .test.fn = npf_orig_iface_unmatch, \
249struct npf_test_size_bounds {
255extern npf_test_fn_t npf_size_inbounds;
265#define NPF_SIZE_MIN(_name, _size) \
266 struct npf_test_size_bounds _name = { \
269 .test.fn = npf_size_inbounds, \
278#define NPF_SIZE_MAX(_name, _size) \
279 struct npf_test_size_bounds _name = { \
282 .test.fn = npf_size_inbounds, \
292#define NPF_SIZE_BOUNDS(_name, _min_size, _max_size) \
293 struct npf_test_size_bounds _name = { \
294 .min = (_min_size), \
295 .max = (_max_size), \
296 .test.fn = npf_size_inbounds, \
309struct npf_test_eth_addr {
311 unsigned int nb_addresses;
312 struct net_eth_addr *addresses;
313 struct net_eth_addr mask;
316extern npf_test_fn_t npf_eth_src_addr_match;
317extern npf_test_fn_t npf_eth_src_addr_unmatch;
318extern npf_test_fn_t npf_eth_dst_addr_match;
319extern npf_test_fn_t npf_eth_dst_addr_unmatch;
332#define NPF_ETH_SRC_ADDR_MATCH(_name, _addr_array) \
333 struct npf_test_eth_addr _name = { \
334 .addresses = (_addr_array), \
335 .nb_addresses = ARRAY_SIZE(_addr_array), \
336 .test.fn = npf_eth_src_addr_match, \
337 .mask.addr = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }, \
349#define NPF_ETH_SRC_ADDR_UNMATCH(_name, _addr_array) \
350 struct npf_test_eth_addr _name = { \
351 .addresses = (_addr_array), \
352 .nb_addresses = ARRAY_SIZE(_addr_array), \
353 .test.fn = npf_eth_src_addr_unmatch, \
354 .mask.addr = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }, \
366#define NPF_ETH_DST_ADDR_MATCH(_name, _addr_array) \
367 struct npf_test_eth_addr _name = { \
368 .addresses = (_addr_array), \
369 .nb_addresses = ARRAY_SIZE(_addr_array), \
370 .test.fn = npf_eth_dst_addr_match, \
371 .mask.addr = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }, \
383#define NPF_ETH_DST_ADDR_UNMATCH(_name, _addr_array) \
384 struct npf_test_eth_addr _name = { \
385 .addresses = (_addr_array), \
386 .nb_addresses = ARRAY_SIZE(_addr_array), \
387 .test.fn = npf_eth_dst_addr_unmatch, \
388 .mask.addr = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }, \
401#define NPF_ETH_SRC_ADDR_MASK_MATCH(_name, _addr_array, ...) \
402 struct npf_test_eth_addr _name = { \
403 .addresses = (_addr_array), \
404 .nb_addresses = ARRAY_SIZE(_addr_array), \
405 .mask.addr = { __VA_ARGS__ }, \
406 .test.fn = npf_eth_src_addr_match, \
419#define NPF_ETH_DST_ADDR_MASK_MATCH(_name, _addr_array, ...) \
420 struct npf_test_eth_addr _name = { \
421 .addresses = (_addr_array), \
422 .nb_addresses = ARRAY_SIZE(_addr_array), \
423 .mask.addr = { __VA_ARGS__ }, \
424 .test.fn = npf_eth_dst_addr_match, \
429struct npf_test_eth_type {
434extern npf_test_fn_t npf_eth_type_match;
435extern npf_test_fn_t npf_eth_type_unmatch;
445#define NPF_ETH_TYPE_MATCH(_name, _type) \
446 struct npf_test_eth_type _name = { \
447 .type = htons(_type), \
448 .test.fn = npf_eth_type_match, \
457#define NPF_ETH_TYPE_UNMATCH(_name, _type) \
458 struct npf_test_eth_type _name = { \
459 .type = htons(_type), \
460 .test.fn = npf_eth_type_unmatch, \
net_verdict
Net Verdict.
Definition: net_core.h:97
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_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.
void npf_append_rule(struct npf_rule_list *rules, struct npf_rule *rule)
Append a rule at the end of given rule list.
Network core definitions.
Single-linked list implementation.
struct _slist sys_slist_t
Definition: slist.h:40
struct _snode sys_snode_t
Definition: slist.h:33
#define bool
Definition: stdbool.h:13
__UINT32_TYPE__ uint32_t
Definition: stdint.h:60
__UINT16_TYPE__ uint16_t
Definition: stdint.h:59
Kernel Spin Lock.
Definition: spinlock.h:42
Network Interface structure.
Definition: net_if.h:468
Network packet.
Definition: net_pkt.h:62
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
Definition: net_pkt_filter.h:51
struct npf_test * tests[]
Definition: net_pkt_filter.h:52
enum net_verdict result
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
Definition: net_pkt_filter.h:44