Zephyr API Documentation 4.5.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
net_pkt_filter.h
Go to the documentation of this file.
1
7
8/*
9 * Copyright (c) 2021 BayLibre SAS
10 *
11 * SPDX-License-Identifier: Apache-2.0
12 */
13
14#ifndef ZEPHYR_INCLUDE_NET_NET_PKT_FILTER_H_
15#define ZEPHYR_INCLUDE_NET_NET_PKT_FILTER_H_
16
17#include <limits.h>
18#include <stdbool.h>
19#include <zephyr/sys/slist.h>
20#include <zephyr/net/net_core.h>
21#include <zephyr/net/ethernet.h>
22
23#ifdef __cplusplus
24extern "C" {
25#endif
26
35
37
38struct npf_test;
39
40typedef bool (npf_test_fn_t)(struct npf_test *test, struct net_pkt *pkt);
41
42enum npf_test_type {
43 NPF_TEST_TYPE_UNKNOWN = 0,
44 NPF_TEST_TYPE_IFACE_MATCH,
45 NPF_TEST_TYPE_IFACE_UNMATCH,
46 NPF_TEST_TYPE_ORIG_IFACE_MATCH,
47 NPF_TEST_TYPE_ORIG_IFACE_UNMATCH,
48 NPF_TEST_TYPE_SIZE_MIN,
49 NPF_TEST_TYPE_SIZE_MAX,
50 NPF_TEST_TYPE_SIZE_BOUNDS,
51 NPF_TEST_TYPE_IP_SRC_ADDR_ALLOWLIST,
52 NPF_TEST_TYPE_IP_SRC_ADDR_BLOCKLIST,
53 NPF_TEST_TYPE_ETH_SRC_ADDR_MATCH,
54 NPF_TEST_TYPE_ETH_SRC_ADDR_UNMATCH,
55 NPF_TEST_TYPE_ETH_DST_ADDR_MATCH,
56 NPF_TEST_TYPE_ETH_DST_ADDR_UNMATCH,
57 NPF_TEST_TYPE_ETH_SRC_ADDR_MASK_MATCH,
58 NPF_TEST_TYPE_ETH_DST_ADDR_MASK_MATCH,
59 NPF_TEST_TYPE_ETH_TYPE_MATCH,
60 NPF_TEST_TYPE_ETH_TYPE_UNMATCH,
61 NPF_TEST_TYPE_ETH_VLAN_TYPE_MATCH,
62 NPF_TEST_TYPE_ETH_VLAN_TYPE_UNMATCH,
63 NPF_TEST_TYPE_LOCAL_IN_MATCH,
64 NPF_TEST_TYPE_UDP_SRC_PORT_MATCH,
65 NPF_TEST_TYPE_UDP_DST_PORT_MATCH,
66 NPF_TEST_TYPE_TCP_SRC_PORT_MATCH,
67 NPF_TEST_TYPE_TCP_DST_PORT_MATCH,
68 NPF_TEST_TYPE_TCP_FLAGS_MATCH,
69};
70
71#if defined(CONFIG_NET_PKT_FILTER_LOG_LEVEL_DBG) || \
72 defined(CONFIG_NET_SHELL_PKT_FILTER_SUPPORTED)
73#define NPF_TEST_ENABLE_NAME 1
74#elif defined(NPF_TEST_ENABLE_NAME)
75#undef NPF_TEST_ENABLE_NAME
76#endif
77
79
81struct npf_test {
82 npf_test_fn_t *fn;
83
85 IF_ENABLED(NPF_TEST_ENABLE_NAME,
86 (const char *name;))
87 IF_ENABLED(NPF_TEST_ENABLE_NAME,
88 (enum npf_test_type type;))
90};
91
100
102extern struct npf_rule npf_default_ok;
104extern struct npf_rule npf_default_drop;
105
111
113extern struct npf_rule_list npf_send_rules;
115extern struct npf_rule_list npf_recv_rules;
122
129void npf_insert_rule(struct npf_rule_list *rules, struct npf_rule *rule);
130
137void npf_append_rule(struct npf_rule_list *rules, struct npf_rule *rule);
138
146bool npf_remove_rule(struct npf_rule_list *rules, struct npf_rule *rule);
147
155
157
158/* convenience shortcuts */
159#define npf_insert_send_rule(rule) npf_insert_rule(&npf_send_rules, rule)
160#define npf_insert_recv_rule(rule) npf_insert_rule(&npf_recv_rules, rule)
161#define npf_append_send_rule(rule) npf_append_rule(&npf_send_rules, rule)
162#define npf_append_recv_rule(rule) npf_append_rule(&npf_recv_rules, rule)
163#define npf_remove_send_rule(rule) npf_remove_rule(&npf_send_rules, rule)
164#define npf_remove_recv_rule(rule) npf_remove_rule(&npf_recv_rules, rule)
165#define npf_remove_all_send_rules() npf_remove_all_rules(&npf_send_rules)
166#define npf_remove_all_recv_rules() npf_remove_all_rules(&npf_recv_rules)
167
168#ifdef CONFIG_NET_PKT_FILTER_LOCAL_IN_HOOK
169#define npf_insert_local_in_recv_rule(rule) npf_insert_rule(&npf_local_in_recv_rules, rule)
170#define npf_append_local_in_recv_rule(rule) npf_append_rule(&npf_local_in_recv_rules, rule)
171#define npf_remove_local_in_recv_rule(rule) npf_remove_rule(&npf_local_in_recv_rules, rule)
172#define npf_remove_all_local_in_recv_rules() npf_remove_all_rules(&npf_local_in_recv_rules)
173#endif /* CONFIG_NET_PKT_FILTER_LOCAL_IN_HOOK */
174
175#ifdef CONFIG_NET_PKT_FILTER_IPV4_HOOK
176#define npf_insert_ipv4_recv_rule(rule) npf_insert_rule(&npf_ipv4_recv_rules, rule)
177#define npf_append_ipv4_recv_rule(rule) npf_append_rule(&npf_ipv4_recv_rules, rule)
178#define npf_remove_ipv4_recv_rule(rule) npf_remove_rule(&npf_ipv4_recv_rules, rule)
179#define npf_remove_all_ipv4_recv_rules() npf_remove_all_rules(&npf_ipv4_recv_rules)
180#endif /* CONFIG_NET_PKT_FILTER_IPV4_HOOK */
181
182#ifdef CONFIG_NET_PKT_FILTER_IPV6_HOOK
183#define npf_insert_ipv6_recv_rule(rule) npf_insert_rule(&npf_ipv6_recv_rules, rule)
184#define npf_append_ipv6_recv_rule(rule) npf_append_rule(&npf_ipv6_recv_rules, rule)
185#define npf_remove_ipv6_recv_rule(rule) npf_remove_rule(&npf_ipv6_recv_rules, rule)
186#define npf_remove_all_ipv6_recv_rules() npf_remove_all_rules(&npf_ipv6_recv_rules)
187#endif /* CONFIG_NET_PKT_FILTER_IPV6_HOOK */
188
190
245#define NPF_RULE(_name, _result, ...) \
246 struct npf_rule _name = { \
247 .result = (_result), \
248 .nb_tests = NUM_VA_ARGS_LESS_1(__VA_ARGS__) + 1, \
249 .tests = { FOR_EACH(Z_NPF_TEST_ADDR, (,), __VA_ARGS__) }, \
250 }
251
252#define NPF_PRIORITY(_name, _priority, ...) \
253 struct npf_rule _name = { \
254 .result = NET_CONTINUE, \
255 .priority = (_priority), \
256 .nb_tests = NUM_VA_ARGS_LESS_1(__VA_ARGS__) + 1, \
257 .tests = {FOR_EACH(Z_NPF_TEST_ADDR, (,), __VA_ARGS__)}, \
258 }
259
260#define Z_NPF_TEST_ADDR(arg) &arg.test
261
263
271
273
274struct npf_test_iface {
275 struct npf_test test;
276 struct net_if *iface;
277};
278
279extern npf_test_fn_t npf_iface_match;
280extern npf_test_fn_t npf_iface_unmatch;
281extern npf_test_fn_t npf_orig_iface_match;
282extern npf_test_fn_t npf_orig_iface_unmatch;
283
285
292#define NPF_IFACE_MATCH(_name, _iface) \
293 struct npf_test_iface _name = { \
294 .iface = (_iface), \
295 .test.fn = npf_iface_match, \
296 IF_ENABLED(NPF_TEST_ENABLE_NAME, \
297 (.test.name = "iface", \
298 .test.type = NPF_TEST_TYPE_IFACE_MATCH,)) \
299 }
300
307#define NPF_IFACE_UNMATCH(_name, _iface) \
308 struct npf_test_iface _name = { \
309 .iface = (_iface), \
310 .test.fn = npf_iface_unmatch, \
311 IF_ENABLED(NPF_TEST_ENABLE_NAME, \
312 (.test.name = "!iface", \
313 .test.type = NPF_TEST_TYPE_IFACE_UNMATCH,)) \
314 }
315
322#define NPF_ORIG_IFACE_MATCH(_name, _iface) \
323 struct npf_test_iface _name = { \
324 .iface = (_iface), \
325 .test.fn = npf_orig_iface_match, \
326 IF_ENABLED(NPF_TEST_ENABLE_NAME, \
327 (.test.name = "orig iface", \
328 .test.type = NPF_TEST_TYPE_ORIG_IFACE_MATCH,)) \
329 }
330
337#define NPF_ORIG_IFACE_UNMATCH(_name, _iface) \
338 struct npf_test_iface _name = { \
339 .iface = (_iface), \
340 .test.fn = npf_orig_iface_unmatch, \
341 IF_ENABLED(NPF_TEST_ENABLE_NAME, \
342 (.test.name = "!orig iface", \
343 .test.type = NPF_TEST_TYPE_ORIG_IFACE_UNMATCH,)) \
344 }
345
347
348struct npf_test_size_bounds {
349 struct npf_test test;
350 size_t min;
351 size_t max;
352};
353
354extern npf_test_fn_t npf_size_inbounds;
355
357
364#define NPF_SIZE_MIN(_name, _size) \
365 struct npf_test_size_bounds _name = { \
366 .min = (_size), \
367 .max = SIZE_MAX, \
368 .test.fn = npf_size_inbounds, \
369 IF_ENABLED(NPF_TEST_ENABLE_NAME, \
370 (.test.name = "size min", \
371 .test.type = NPF_TEST_TYPE_SIZE_MIN,)) \
372 }
373
380#define NPF_SIZE_MAX(_name, _size) \
381 struct npf_test_size_bounds _name = { \
382 .min = 0, \
383 .max = (_size), \
384 .test.fn = npf_size_inbounds, \
385 IF_ENABLED(NPF_TEST_ENABLE_NAME, \
386 (.test.name = "size max", \
387 .test.type = NPF_TEST_TYPE_SIZE_MAX,)) \
388 }
389
397#define NPF_SIZE_BOUNDS(_name, _min_size, _max_size) \
398 struct npf_test_size_bounds _name = { \
399 .min = (_min_size), \
400 .max = (_max_size), \
401 .test.fn = npf_size_inbounds, \
402 IF_ENABLED(NPF_TEST_ENABLE_NAME, \
403 (.test.name = "size bounds", \
404 .test.type = NPF_TEST_TYPE_SIZE_BOUNDS,)) \
405 }
406
408
409struct npf_test_ip {
410 struct npf_test test;
411 uint8_t addr_family;
412 void *ipaddr;
413 uint32_t ipaddr_num;
414};
415
416extern npf_test_fn_t npf_ip_src_addr_match;
417extern npf_test_fn_t npf_ip_src_addr_unmatch;
418
420
436#define NPF_IP_SRC_ADDR_ALLOWLIST(_name, _ip_addr_array, _ip_addr_num, _af) \
437 struct npf_test_ip _name = { \
438 .addr_family = _af, \
439 .ipaddr = (_ip_addr_array), \
440 .ipaddr_num = _ip_addr_num, \
441 .test.fn = npf_ip_src_addr_match, \
442 IF_ENABLED(NPF_TEST_ENABLE_NAME, \
443 (.test.name = "ip src allow", \
444 .test.type = NPF_TEST_TYPE_IP_SRC_ADDR_ALLOWLIST,)) \
445 }
446
462#define NPF_IP_SRC_ADDR_BLOCKLIST(_name, _ip_addr_array, _ip_addr_num, _af) \
463 struct npf_test_ip _name = { \
464 .addr_family = _af, \
465 .ipaddr = (_ip_addr_array), \
466 .ipaddr_num = _ip_addr_num, \
467 .test.fn = npf_ip_src_addr_unmatch, \
468 IF_ENABLED(NPF_TEST_ENABLE_NAME, \
469 (.test.name = "ip src block", \
470 .test.type = NPF_TEST_TYPE_IP_SRC_ADDR_BLOCKLIST,)) \
471 }
472
474
482
484
485struct npf_test_eth_addr {
486 struct npf_test test;
487 unsigned int nb_addresses;
488 struct net_eth_addr *addresses;
489 struct net_eth_addr mask;
490};
491
492extern npf_test_fn_t npf_eth_src_addr_match;
493extern npf_test_fn_t npf_eth_src_addr_unmatch;
494extern npf_test_fn_t npf_eth_dst_addr_match;
495extern npf_test_fn_t npf_eth_dst_addr_unmatch;
496
498
508#define NPF_ETH_SRC_ADDR_MATCH(_name, _addr_array) \
509 struct npf_test_eth_addr _name = { \
510 .addresses = (_addr_array), \
511 .nb_addresses = ARRAY_SIZE(_addr_array), \
512 .test.fn = npf_eth_src_addr_match, \
513 .mask.addr = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }, \
514 IF_ENABLED(NPF_TEST_ENABLE_NAME, \
515 (.test.name = "eth src", \
516 .test.type = NPF_TEST_TYPE_ETH_SRC_ADDR_MATCH,)) \
517 }
518
528#define NPF_ETH_SRC_ADDR_UNMATCH(_name, _addr_array) \
529 struct npf_test_eth_addr _name = { \
530 .addresses = (_addr_array), \
531 .nb_addresses = ARRAY_SIZE(_addr_array), \
532 .test.fn = npf_eth_src_addr_unmatch, \
533 .mask.addr = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }, \
534 IF_ENABLED(NPF_TEST_ENABLE_NAME, \
535 (.test.name = "!eth src", \
536 .test.type = NPF_TEST_TYPE_ETH_SRC_ADDR_UNMATCH,)) \
537 }
538
548#define NPF_ETH_DST_ADDR_MATCH(_name, _addr_array) \
549 struct npf_test_eth_addr _name = { \
550 .addresses = (_addr_array), \
551 .nb_addresses = ARRAY_SIZE(_addr_array), \
552 .test.fn = npf_eth_dst_addr_match, \
553 .mask.addr = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }, \
554 IF_ENABLED(NPF_TEST_ENABLE_NAME, \
555 (.test.name = "eth dst", \
556 .test.type = NPF_TEST_TYPE_ETH_DST_ADDR_MATCH,)) \
557 }
558
568#define NPF_ETH_DST_ADDR_UNMATCH(_name, _addr_array) \
569 struct npf_test_eth_addr _name = { \
570 .addresses = (_addr_array), \
571 .nb_addresses = ARRAY_SIZE(_addr_array), \
572 .test.fn = npf_eth_dst_addr_unmatch, \
573 .mask.addr = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }, \
574 IF_ENABLED(NPF_TEST_ENABLE_NAME, \
575 (.test.name = "!eth dst", \
576 .test.type = NPF_TEST_TYPE_ETH_DST_ADDR_UNMATCH,)) \
577 }
578
589#define NPF_ETH_SRC_ADDR_MASK_MATCH(_name, _addr_array, ...) \
590 struct npf_test_eth_addr _name = { \
591 .addresses = (_addr_array), \
592 .nb_addresses = ARRAY_SIZE(_addr_array), \
593 .mask.addr = { __VA_ARGS__ }, \
594 .test.fn = npf_eth_src_addr_match, \
595 IF_ENABLED(NPF_TEST_ENABLE_NAME, \
596 (.test.name = "eth src mask", \
597 .test.type = NPF_TEST_TYPE_ETH_SRC_ADDR_MASK_MATCH,)) \
598 }
599
610#define NPF_ETH_DST_ADDR_MASK_MATCH(_name, _addr_array, ...) \
611 struct npf_test_eth_addr _name = { \
612 .addresses = (_addr_array), \
613 .nb_addresses = ARRAY_SIZE(_addr_array), \
614 .mask.addr = { __VA_ARGS__ }, \
615 .test.fn = npf_eth_dst_addr_match, \
616 IF_ENABLED(NPF_TEST_ENABLE_NAME, \
617 (.test.name = "eth dst mask", \
618 .test.type = NPF_TEST_TYPE_ETH_DST_ADDR_MASK_MATCH,)) \
619 }
620
622
623struct npf_test_eth_type {
624 struct npf_test test;
625 uint16_t type; /* type in network order */
626};
627
628extern npf_test_fn_t npf_eth_type_match;
629extern npf_test_fn_t npf_eth_type_unmatch;
630extern npf_test_fn_t npf_eth_vlan_type_match;
631extern npf_test_fn_t npf_eth_vlan_type_unmatch;
632
634
641#define NPF_ETH_TYPE_MATCH(_name, _type) \
642 struct npf_test_eth_type _name = { \
643 .type = net_htons(_type), \
644 .test.fn = npf_eth_type_match, \
645 IF_ENABLED(NPF_TEST_ENABLE_NAME, \
646 (.test.name = "eth type", \
647 .test.type = NPF_TEST_TYPE_ETH_TYPE_MATCH,)) \
648 }
649
656#define NPF_ETH_TYPE_UNMATCH(_name, _type) \
657 struct npf_test_eth_type _name = { \
658 .type = net_htons(_type), \
659 .test.fn = npf_eth_type_unmatch, \
660 IF_ENABLED(NPF_TEST_ENABLE_NAME, \
661 (.test.name = "!eth type", \
662 .test.type = NPF_TEST_TYPE_ETH_TYPE_UNMATCH,)) \
663 }
664
672#define NPF_ETH_VLAN_TYPE_MATCH(_name, _type) \
673 struct npf_test_eth_type _name = { \
674 .type = net_htons(_type), \
675 .test.fn = npf_eth_vlan_type_match, \
676 IF_ENABLED(NPF_TEST_ENABLE_NAME, \
677 (.test.name = "eth vlan type", \
678 .test.type = NPF_TEST_TYPE_ETH_VLAN_TYPE_MATCH,)) \
679 }
680
688#define NPF_ETH_VLAN_TYPE_UNMATCH(_name, _type) \
689 struct npf_test_eth_type _name = { \
690 .type = net_htons(_type), \
691 .test.fn = npf_eth_vlan_type_unmatch, \
692 IF_ENABLED(NPF_TEST_ENABLE_NAME, \
693 (.test.name = "!eth vlan type", \
694 .test.type = NPF_TEST_TYPE_ETH_VLAN_TYPE_UNMATCH,)) \
695 }
696
708typedef bool (npf_local_in_fn_t)(struct net_pkt *pkt, void *user_data);
709
711
712extern npf_test_fn_t npf_local_in_match;
713
714struct npf_test_local_in {
715 struct npf_test test;
716 npf_local_in_fn_t *fn; /* local_in hook function */
717 void *user_data; /* optional user data */
718};
719
721
729#define NPF_LOCAL_IN_MATCH(_name, _handler, _user_data) \
730 struct npf_test_local_in _name = { \
731 .test.fn = npf_local_in_match, \
732 .fn = (_handler), \
733 .user_data = (_user_data), \
734 IF_ENABLED(NPF_TEST_ENABLE_NAME, \
735 (.test.name = "local_in", \
736 .test.type = NPF_TEST_TYPE_LOCAL_IN_MATCH,)) \
737 }
738
748
757typedef void (*npf_rule_cb_t)(struct npf_rule *rule,
758 enum npf_rule_type type,
759 void *user_data);
760
768void npf_rules_foreach(npf_rule_cb_t cb, void *user_data);
769
771const char *npf_test_get_str(struct npf_test *test, char *buf,
772 size_t len);
774
776
789
791
792struct npf_test_port {
793 struct npf_test test;
794 uint16_t port; /* port in network order */
795 uint8_t proto;
796};
797
798extern npf_test_fn_t npf_src_port_match;
799extern npf_test_fn_t npf_dst_port_match;
800
802
811#define NPF_UDP_SRC_PORT_MATCH(_name, _port) \
812 struct npf_test_port _name = { \
813 .proto = NET_IPPROTO_UDP, \
814 .port = net_htons(_port), \
815 .test.fn = npf_src_port_match, \
816 IF_ENABLED(NPF_TEST_ENABLE_NAME, \
817 (.test.name = "udp src port", \
818 .test.type = NPF_TEST_TYPE_UDP_SRC_PORT_MATCH,)) \
819 }
820
829#define NPF_UDP_DST_PORT_MATCH(_name, _port) \
830 struct npf_test_port _name = { \
831 .proto = NET_IPPROTO_UDP, \
832 .port = net_htons(_port), \
833 .test.fn = npf_dst_port_match, \
834 IF_ENABLED(NPF_TEST_ENABLE_NAME, \
835 (.test.name = "udp dst port", \
836 .test.type = NPF_TEST_TYPE_UDP_DST_PORT_MATCH,)) \
837 }
838
840
853
855
856struct npf_test_tcp_flags {
857 struct npf_test test;
858 uint8_t mask;
860};
861
862extern npf_test_fn_t npf_tcp_flags_match;
863
865
874#define NPF_TCP_SRC_PORT_MATCH(_name, _port) \
875 struct npf_test_port _name = { \
876 .proto = NET_IPPROTO_TCP, \
877 .port = net_htons(_port), \
878 .test.fn = npf_src_port_match, \
879 IF_ENABLED(NPF_TEST_ENABLE_NAME, \
880 (.test.name = "tcp src port", \
881 .test.type = NPF_TEST_TYPE_TCP_SRC_PORT_MATCH,)) \
882 }
883
892#define NPF_TCP_DST_PORT_MATCH(_name, _port) \
893 struct npf_test_port _name = { \
894 .proto = NET_IPPROTO_TCP, \
895 .port = net_htons(_port), \
896 .test.fn = npf_dst_port_match, \
897 IF_ENABLED(NPF_TEST_ENABLE_NAME, \
898 (.test.name = "tcp dst port", \
899 .test.type = NPF_TEST_TYPE_TCP_DST_PORT_MATCH,)) \
900 }
901
909#define NPF_TCP_FLAG_FIN BIT(0)
910#define NPF_TCP_FLAG_SYN BIT(1)
911#define NPF_TCP_FLAG_RST BIT(2)
912#define NPF_TCP_FLAG_PSH BIT(3)
913#define NPF_TCP_FLAG_ACK BIT(4)
914#define NPF_TCP_FLAG_URG BIT(5)
915#define NPF_TCP_FLAG_ECE BIT(6)
916#define NPF_TCP_FLAG_CWR BIT(7)
918
935#define NPF_TCP_FLAGS_MATCH(_name, _mask, _flags) \
936 struct npf_test_tcp_flags _name = { \
937 .mask = (_mask), \
938 .flags = (_flags) + ZERO_OR_COMPILE_ERROR(((_flags) & ~(_mask)) == 0), \
939 .test.fn = npf_tcp_flags_match, \
940 IF_ENABLED(NPF_TEST_ENABLE_NAME, \
941 (.test.name = "tcp flags", \
942 .test.type = NPF_TEST_TYPE_TCP_FLAGS_MATCH,)) \
943 }
944
946
947#ifdef __cplusplus
948}
949#endif
950
951#endif /* ZEPHYR_INCLUDE_NET_NET_PKT_FILTER_H_ */
Ethernet.
net_priority
Network packet priority settings described in IEEE 802.1Q Annex I.1.
Definition net_ip.h:567
net_verdict
Net Verdict.
Definition net_core.h:84
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.
void npf_rules_foreach(npf_rule_cb_t cb, void *user_data)
Go through all the network packet filter rules and call callback for each of them.
bool npf_local_in_fn_t(struct net_pkt *pkt, void *user_data)
Function that is called to get the verdict what should happen to the network packet.
Definition net_pkt_filter.h:708
void(* npf_rule_cb_t)(struct npf_rule *rule, enum npf_rule_type type, void *user_data)
Callback used while iterating over network packet filter rules.
Definition net_pkt_filter.h:757
npf_rule_type
Type of the packet filter rule.
Definition net_pkt_filter.h:740
@ NPF_RULE_TYPE_UNKNOWN
Unknown rule type.
Definition net_pkt_filter.h:741
@ NPF_RULE_TYPE_RECV
Rule for incoming packets.
Definition net_pkt_filter.h:743
@ NPF_RULE_TYPE_LOCAL_IN_RECV
Rule for local incoming packets.
Definition net_pkt_filter.h:744
@ NPF_RULE_TYPE_SEND
Rule for outgoing packets.
Definition net_pkt_filter.h:742
@ NPF_RULE_TYPE_IPV4_RECV
Rule for IPv4 incoming packets.
Definition net_pkt_filter.h:745
@ NPF_RULE_TYPE_IPV6_RECV
Rule for IPv6 incoming packets.
Definition net_pkt_filter.h:746
struct _slist sys_slist_t
Single-linked list structure.
Definition slist.h:54
struct _snode sys_snode_t
Single-linked list node structure.
Definition slist.h:44
#define IF_ENABLED(_flag, _code)
Insert code if _flag is defined and equals 1.
Definition util_macro.h:290
#define min(a, b)
Return smaller value of two provided expressions.
Definition minmax.h:81
#define max(a, b)
Return larger value of two provided expressions.
Definition minmax.h:65
Network core definitions.
flags
Definition parser.h:86
Header file for the single-linked list API.
#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
Ethernet address.
Definition ethernet.h:51
Network Interface structure.
Definition net_if.h:875
Network packet.
Definition net_pkt.h:119
rule set for a given test location
Definition net_pkt_filter.h:107
sys_slist_t rule_head
List head.
Definition net_pkt_filter.h:108
struct k_spinlock lock
Lock protecting the list access.
Definition net_pkt_filter.h:109
filter rule structure
Definition net_pkt_filter.h:93
uint32_t nb_tests
number of tests for this rule
Definition net_pkt_filter.h:97
enum net_priority priority
priority in case of NET_CONTINUE
Definition net_pkt_filter.h:96
struct npf_test * tests[]
pointers to npf_test instances
Definition net_pkt_filter.h:98
enum net_verdict result
result if all tests pass
Definition net_pkt_filter.h:95
sys_snode_t node
Slist rule list node.
Definition net_pkt_filter.h:94
common filter test structure to be embedded into larger structures
Definition net_pkt_filter.h:81
npf_test_fn_t * fn
packet condition test function
Definition net_pkt_filter.h:82