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
165
174typedef void (*npf_rule_cb_t)(struct npf_rule *rule,
175 enum npf_rule_type type,
176 void *user_data);
177
185void npf_rules_foreach(npf_rule_cb_t cb, void *user_data);
186
188const char *npf_test_get_str(struct npf_test *test, char *buf,
189 size_t len);
191
193
194/* convenience shortcuts */
195#define npf_insert_send_rule(rule) npf_insert_rule(&npf_send_rules, rule)
196#define npf_insert_recv_rule(rule) npf_insert_rule(&npf_recv_rules, rule)
197#define npf_append_send_rule(rule) npf_append_rule(&npf_send_rules, rule)
198#define npf_append_recv_rule(rule) npf_append_rule(&npf_recv_rules, rule)
199#define npf_remove_send_rule(rule) npf_remove_rule(&npf_send_rules, rule)
200#define npf_remove_recv_rule(rule) npf_remove_rule(&npf_recv_rules, rule)
201#define npf_remove_all_send_rules() npf_remove_all_rules(&npf_send_rules)
202#define npf_remove_all_recv_rules() npf_remove_all_rules(&npf_recv_rules)
203
204#ifdef CONFIG_NET_PKT_FILTER_LOCAL_IN_HOOK
205#define npf_insert_local_in_recv_rule(rule) npf_insert_rule(&npf_local_in_recv_rules, rule)
206#define npf_append_local_in_recv_rule(rule) npf_append_rule(&npf_local_in_recv_rules, rule)
207#define npf_remove_local_in_recv_rule(rule) npf_remove_rule(&npf_local_in_recv_rules, rule)
208#define npf_remove_all_local_in_recv_rules() npf_remove_all_rules(&npf_local_in_recv_rules)
209#endif /* CONFIG_NET_PKT_FILTER_LOCAL_IN_HOOK */
210
211#ifdef CONFIG_NET_PKT_FILTER_IPV4_HOOK
212#define npf_insert_ipv4_recv_rule(rule) npf_insert_rule(&npf_ipv4_recv_rules, rule)
213#define npf_append_ipv4_recv_rule(rule) npf_append_rule(&npf_ipv4_recv_rules, rule)
214#define npf_remove_ipv4_recv_rule(rule) npf_remove_rule(&npf_ipv4_recv_rules, rule)
215#define npf_remove_all_ipv4_recv_rules() npf_remove_all_rules(&npf_ipv4_recv_rules)
216#endif /* CONFIG_NET_PKT_FILTER_IPV4_HOOK */
217
218#ifdef CONFIG_NET_PKT_FILTER_IPV6_HOOK
219#define npf_insert_ipv6_recv_rule(rule) npf_insert_rule(&npf_ipv6_recv_rules, rule)
220#define npf_append_ipv6_recv_rule(rule) npf_append_rule(&npf_ipv6_recv_rules, rule)
221#define npf_remove_ipv6_recv_rule(rule) npf_remove_rule(&npf_ipv6_recv_rules, rule)
222#define npf_remove_all_ipv6_recv_rules() npf_remove_all_rules(&npf_ipv6_recv_rules)
223#endif /* CONFIG_NET_PKT_FILTER_IPV6_HOOK */
224
226
281#define NPF_RULE(_name, _result, ...) \
282 struct npf_rule _name = { \
283 .result = (_result), \
284 .nb_tests = NUM_VA_ARGS_LESS_1(__VA_ARGS__) + 1, \
285 .tests = { FOR_EACH(Z_NPF_TEST_ADDR, (,), __VA_ARGS__) }, \
286 }
287
324#define NPF_PRIORITY(_name, _priority, ...) \
325 struct npf_rule _name = { \
326 .result = NET_CONTINUE, \
327 .priority = (_priority), \
328 .nb_tests = NUM_VA_ARGS_LESS_1(__VA_ARGS__) + 1, \
329 .tests = {FOR_EACH(Z_NPF_TEST_ADDR, (,), __VA_ARGS__)}, \
330 }
331
332#define Z_NPF_TEST_ADDR(arg) &arg.test
333
335
343
345
346struct npf_test_iface {
347 struct npf_test test;
348 struct net_if *iface;
349};
350
351extern npf_test_fn_t npf_iface_match;
352extern npf_test_fn_t npf_iface_unmatch;
353extern npf_test_fn_t npf_orig_iface_match;
354extern npf_test_fn_t npf_orig_iface_unmatch;
355
357
364#define NPF_IFACE_MATCH(_name, _iface) \
365 struct npf_test_iface _name = { \
366 .iface = (_iface), \
367 .test.fn = npf_iface_match, \
368 IF_ENABLED(NPF_TEST_ENABLE_NAME, \
369 (.test.name = "iface", \
370 .test.type = NPF_TEST_TYPE_IFACE_MATCH,)) \
371 }
372
379#define NPF_IFACE_UNMATCH(_name, _iface) \
380 struct npf_test_iface _name = { \
381 .iface = (_iface), \
382 .test.fn = npf_iface_unmatch, \
383 IF_ENABLED(NPF_TEST_ENABLE_NAME, \
384 (.test.name = "!iface", \
385 .test.type = NPF_TEST_TYPE_IFACE_UNMATCH,)) \
386 }
387
394#define NPF_ORIG_IFACE_MATCH(_name, _iface) \
395 struct npf_test_iface _name = { \
396 .iface = (_iface), \
397 .test.fn = npf_orig_iface_match, \
398 IF_ENABLED(NPF_TEST_ENABLE_NAME, \
399 (.test.name = "orig iface", \
400 .test.type = NPF_TEST_TYPE_ORIG_IFACE_MATCH,)) \
401 }
402
409#define NPF_ORIG_IFACE_UNMATCH(_name, _iface) \
410 struct npf_test_iface _name = { \
411 .iface = (_iface), \
412 .test.fn = npf_orig_iface_unmatch, \
413 IF_ENABLED(NPF_TEST_ENABLE_NAME, \
414 (.test.name = "!orig iface", \
415 .test.type = NPF_TEST_TYPE_ORIG_IFACE_UNMATCH,)) \
416 }
417
419
420struct npf_test_size_bounds {
421 struct npf_test test;
422 size_t min;
423 size_t max;
424};
425
426extern npf_test_fn_t npf_size_inbounds;
427
429
436#define NPF_SIZE_MIN(_name, _size) \
437 struct npf_test_size_bounds _name = { \
438 .min = (_size), \
439 .max = SIZE_MAX, \
440 .test.fn = npf_size_inbounds, \
441 IF_ENABLED(NPF_TEST_ENABLE_NAME, \
442 (.test.name = "size min", \
443 .test.type = NPF_TEST_TYPE_SIZE_MIN,)) \
444 }
445
452#define NPF_SIZE_MAX(_name, _size) \
453 struct npf_test_size_bounds _name = { \
454 .min = 0, \
455 .max = (_size), \
456 .test.fn = npf_size_inbounds, \
457 IF_ENABLED(NPF_TEST_ENABLE_NAME, \
458 (.test.name = "size max", \
459 .test.type = NPF_TEST_TYPE_SIZE_MAX,)) \
460 }
461
469#define NPF_SIZE_BOUNDS(_name, _min_size, _max_size) \
470 struct npf_test_size_bounds _name = { \
471 .min = (_min_size), \
472 .max = (_max_size), \
473 .test.fn = npf_size_inbounds, \
474 IF_ENABLED(NPF_TEST_ENABLE_NAME, \
475 (.test.name = "size bounds", \
476 .test.type = NPF_TEST_TYPE_SIZE_BOUNDS,)) \
477 }
478
490typedef bool (npf_local_in_fn_t)(struct net_pkt *pkt, void *user_data);
491
493
494extern npf_test_fn_t npf_local_in_match;
495
496struct npf_test_local_in {
497 struct npf_test test;
498 npf_local_in_fn_t *fn; /* local_in hook function */
499 void *user_data; /* optional user data */
500};
501
503
514#define NPF_LOCAL_IN_MATCH(_name, _handler, _user_data) \
515 struct npf_test_local_in _name = { \
516 .test.fn = npf_local_in_match, \
517 .fn = (_handler), \
518 .user_data = (_user_data), \
519 IF_ENABLED(NPF_TEST_ENABLE_NAME, \
520 (.test.name = "local_in", \
521 .test.type = NPF_TEST_TYPE_LOCAL_IN_MATCH,)) \
522 }
523
525
533
535
536struct npf_test_eth_addr {
537 struct npf_test test;
538 unsigned int nb_addresses;
539 struct net_eth_addr *addresses;
540 struct net_eth_addr mask;
541};
542
543extern npf_test_fn_t npf_eth_src_addr_match;
544extern npf_test_fn_t npf_eth_src_addr_unmatch;
545extern npf_test_fn_t npf_eth_dst_addr_match;
546extern npf_test_fn_t npf_eth_dst_addr_unmatch;
547
549
559#define NPF_ETH_SRC_ADDR_MATCH(_name, _addr_array) \
560 struct npf_test_eth_addr _name = { \
561 .addresses = (_addr_array), \
562 .nb_addresses = ARRAY_SIZE(_addr_array), \
563 .test.fn = npf_eth_src_addr_match, \
564 .mask.addr = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }, \
565 IF_ENABLED(NPF_TEST_ENABLE_NAME, \
566 (.test.name = "eth src", \
567 .test.type = NPF_TEST_TYPE_ETH_SRC_ADDR_MATCH,)) \
568 }
569
579#define NPF_ETH_SRC_ADDR_UNMATCH(_name, _addr_array) \
580 struct npf_test_eth_addr _name = { \
581 .addresses = (_addr_array), \
582 .nb_addresses = ARRAY_SIZE(_addr_array), \
583 .test.fn = npf_eth_src_addr_unmatch, \
584 .mask.addr = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }, \
585 IF_ENABLED(NPF_TEST_ENABLE_NAME, \
586 (.test.name = "!eth src", \
587 .test.type = NPF_TEST_TYPE_ETH_SRC_ADDR_UNMATCH,)) \
588 }
589
599#define NPF_ETH_DST_ADDR_MATCH(_name, _addr_array) \
600 struct npf_test_eth_addr _name = { \
601 .addresses = (_addr_array), \
602 .nb_addresses = ARRAY_SIZE(_addr_array), \
603 .test.fn = npf_eth_dst_addr_match, \
604 .mask.addr = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }, \
605 IF_ENABLED(NPF_TEST_ENABLE_NAME, \
606 (.test.name = "eth dst", \
607 .test.type = NPF_TEST_TYPE_ETH_DST_ADDR_MATCH,)) \
608 }
609
619#define NPF_ETH_DST_ADDR_UNMATCH(_name, _addr_array) \
620 struct npf_test_eth_addr _name = { \
621 .addresses = (_addr_array), \
622 .nb_addresses = ARRAY_SIZE(_addr_array), \
623 .test.fn = npf_eth_dst_addr_unmatch, \
624 .mask.addr = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }, \
625 IF_ENABLED(NPF_TEST_ENABLE_NAME, \
626 (.test.name = "!eth dst", \
627 .test.type = NPF_TEST_TYPE_ETH_DST_ADDR_UNMATCH,)) \
628 }
629
640#define NPF_ETH_SRC_ADDR_MASK_MATCH(_name, _addr_array, ...) \
641 struct npf_test_eth_addr _name = { \
642 .addresses = (_addr_array), \
643 .nb_addresses = ARRAY_SIZE(_addr_array), \
644 .mask.addr = { __VA_ARGS__ }, \
645 .test.fn = npf_eth_src_addr_match, \
646 IF_ENABLED(NPF_TEST_ENABLE_NAME, \
647 (.test.name = "eth src mask", \
648 .test.type = NPF_TEST_TYPE_ETH_SRC_ADDR_MASK_MATCH,)) \
649 }
650
661#define NPF_ETH_DST_ADDR_MASK_MATCH(_name, _addr_array, ...) \
662 struct npf_test_eth_addr _name = { \
663 .addresses = (_addr_array), \
664 .nb_addresses = ARRAY_SIZE(_addr_array), \
665 .mask.addr = { __VA_ARGS__ }, \
666 .test.fn = npf_eth_dst_addr_match, \
667 IF_ENABLED(NPF_TEST_ENABLE_NAME, \
668 (.test.name = "eth dst mask", \
669 .test.type = NPF_TEST_TYPE_ETH_DST_ADDR_MASK_MATCH,)) \
670 }
671
673
674struct npf_test_eth_type {
675 struct npf_test test;
676 uint16_t type; /* type in network order */
677};
678
679extern npf_test_fn_t npf_eth_type_match;
680extern npf_test_fn_t npf_eth_type_unmatch;
681extern npf_test_fn_t npf_eth_vlan_type_match;
682extern npf_test_fn_t npf_eth_vlan_type_unmatch;
683
685
692#define NPF_ETH_TYPE_MATCH(_name, _type) \
693 struct npf_test_eth_type _name = { \
694 .type = net_htons(_type), \
695 .test.fn = npf_eth_type_match, \
696 IF_ENABLED(NPF_TEST_ENABLE_NAME, \
697 (.test.name = "eth type", \
698 .test.type = NPF_TEST_TYPE_ETH_TYPE_MATCH,)) \
699 }
700
707#define NPF_ETH_TYPE_UNMATCH(_name, _type) \
708 struct npf_test_eth_type _name = { \
709 .type = net_htons(_type), \
710 .test.fn = npf_eth_type_unmatch, \
711 IF_ENABLED(NPF_TEST_ENABLE_NAME, \
712 (.test.name = "!eth type", \
713 .test.type = NPF_TEST_TYPE_ETH_TYPE_UNMATCH,)) \
714 }
715
723#define NPF_ETH_VLAN_TYPE_MATCH(_name, _type) \
724 struct npf_test_eth_type _name = { \
725 .type = net_htons(_type), \
726 .test.fn = npf_eth_vlan_type_match, \
727 IF_ENABLED(NPF_TEST_ENABLE_NAME, \
728 (.test.name = "eth vlan type", \
729 .test.type = NPF_TEST_TYPE_ETH_VLAN_TYPE_MATCH,)) \
730 }
731
739#define NPF_ETH_VLAN_TYPE_UNMATCH(_name, _type) \
740 struct npf_test_eth_type _name = { \
741 .type = net_htons(_type), \
742 .test.fn = npf_eth_vlan_type_unmatch, \
743 IF_ENABLED(NPF_TEST_ENABLE_NAME, \
744 (.test.name = "!eth vlan type", \
745 .test.type = NPF_TEST_TYPE_ETH_VLAN_TYPE_UNMATCH,)) \
746 }
747
749
757
759
760struct npf_test_ip {
761 struct npf_test test;
762 uint8_t addr_family;
763 void *ipaddr;
764 uint32_t ipaddr_num;
765};
766
767extern npf_test_fn_t npf_ip_src_addr_match;
768extern npf_test_fn_t npf_ip_src_addr_unmatch;
769
771
787#define NPF_IP_SRC_ADDR_ALLOWLIST(_name, _ip_addr_array, _ip_addr_num, _af) \
788 struct npf_test_ip _name = { \
789 .addr_family = _af, \
790 .ipaddr = (_ip_addr_array), \
791 .ipaddr_num = _ip_addr_num, \
792 .test.fn = npf_ip_src_addr_match, \
793 IF_ENABLED(NPF_TEST_ENABLE_NAME, \
794 (.test.name = "ip src allow", \
795 .test.type = NPF_TEST_TYPE_IP_SRC_ADDR_ALLOWLIST,)) \
796 }
797
813#define NPF_IP_SRC_ADDR_BLOCKLIST(_name, _ip_addr_array, _ip_addr_num, _af) \
814 struct npf_test_ip _name = { \
815 .addr_family = _af, \
816 .ipaddr = (_ip_addr_array), \
817 .ipaddr_num = _ip_addr_num, \
818 .test.fn = npf_ip_src_addr_unmatch, \
819 IF_ENABLED(NPF_TEST_ENABLE_NAME, \
820 (.test.name = "ip src block", \
821 .test.type = NPF_TEST_TYPE_IP_SRC_ADDR_BLOCKLIST,)) \
822 }
823
825
838
840
841struct npf_test_port {
842 struct npf_test test;
843 uint16_t port; /* port in network order */
844 uint8_t proto;
845};
846
847extern npf_test_fn_t npf_src_port_match;
848extern npf_test_fn_t npf_dst_port_match;
849
851
860#define NPF_UDP_SRC_PORT_MATCH(_name, _port) \
861 struct npf_test_port _name = { \
862 .proto = NET_IPPROTO_UDP, \
863 .port = net_htons(_port), \
864 .test.fn = npf_src_port_match, \
865 IF_ENABLED(NPF_TEST_ENABLE_NAME, \
866 (.test.name = "udp src port", \
867 .test.type = NPF_TEST_TYPE_UDP_SRC_PORT_MATCH,)) \
868 }
869
878#define NPF_UDP_DST_PORT_MATCH(_name, _port) \
879 struct npf_test_port _name = { \
880 .proto = NET_IPPROTO_UDP, \
881 .port = net_htons(_port), \
882 .test.fn = npf_dst_port_match, \
883 IF_ENABLED(NPF_TEST_ENABLE_NAME, \
884 (.test.name = "udp dst port", \
885 .test.type = NPF_TEST_TYPE_UDP_DST_PORT_MATCH,)) \
886 }
887
889
902
904
905struct npf_test_tcp_flags {
906 struct npf_test test;
907 uint8_t mask;
909};
910
911extern npf_test_fn_t npf_tcp_flags_match;
912
914
923#define NPF_TCP_SRC_PORT_MATCH(_name, _port) \
924 struct npf_test_port _name = { \
925 .proto = NET_IPPROTO_TCP, \
926 .port = net_htons(_port), \
927 .test.fn = npf_src_port_match, \
928 IF_ENABLED(NPF_TEST_ENABLE_NAME, \
929 (.test.name = "tcp src port", \
930 .test.type = NPF_TEST_TYPE_TCP_SRC_PORT_MATCH,)) \
931 }
932
941#define NPF_TCP_DST_PORT_MATCH(_name, _port) \
942 struct npf_test_port _name = { \
943 .proto = NET_IPPROTO_TCP, \
944 .port = net_htons(_port), \
945 .test.fn = npf_dst_port_match, \
946 IF_ENABLED(NPF_TEST_ENABLE_NAME, \
947 (.test.name = "tcp dst port", \
948 .test.type = NPF_TEST_TYPE_TCP_DST_PORT_MATCH,)) \
949 }
950
958#define NPF_TCP_FLAG_FIN BIT(0)
959#define NPF_TCP_FLAG_SYN BIT(1)
960#define NPF_TCP_FLAG_RST BIT(2)
961#define NPF_TCP_FLAG_PSH BIT(3)
962#define NPF_TCP_FLAG_ACK BIT(4)
963#define NPF_TCP_FLAG_URG BIT(5)
964#define NPF_TCP_FLAG_ECE BIT(6)
965#define NPF_TCP_FLAG_CWR BIT(7)
967
984#define NPF_TCP_FLAGS_MATCH(_name, _mask, _flags) \
985 struct npf_test_tcp_flags _name = { \
986 .mask = (_mask), \
987 .flags = (_flags) + ZERO_OR_COMPILE_ERROR(((_flags) & ~(_mask)) == 0), \
988 .test.fn = npf_tcp_flags_match, \
989 IF_ENABLED(NPF_TEST_ENABLE_NAME, \
990 (.test.name = "tcp flags", \
991 .test.type = NPF_TEST_TYPE_TCP_FLAGS_MATCH,)) \
992 }
993
995
996#ifdef __cplusplus
997}
998#endif
999
1000#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_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.
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
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:174
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.
npf_rule_type
Type of the packet filter rule.
Definition net_pkt_filter.h:157
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.
@ NPF_RULE_TYPE_UNKNOWN
Unknown rule type.
Definition net_pkt_filter.h:158
@ NPF_RULE_TYPE_RECV
Rule for incoming packets.
Definition net_pkt_filter.h:160
@ NPF_RULE_TYPE_LOCAL_IN_RECV
Rule for local incoming packets.
Definition net_pkt_filter.h:161
@ NPF_RULE_TYPE_SEND
Rule for outgoing packets.
Definition net_pkt_filter.h:159
@ NPF_RULE_TYPE_IPV4_RECV
Rule for IPv4 incoming packets.
Definition net_pkt_filter.h:162
@ NPF_RULE_TYPE_IPV6_RECV
Rule for IPv6 incoming packets.
Definition net_pkt_filter.h:163
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:490
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