@@ -41,15 +41,15 @@ typedef bool (npf_test_fn_t)(struct npf_test *test, struct net_pkt *pkt);
4141
4242/** @brief common filter test structure to be embedded into larger structures */
4343struct npf_test {
44- npf_test_fn_t * fn ; /*< packet condition test function */
44+ npf_test_fn_t * fn ; /** < packet condition test function */
4545};
4646
4747/** @brief filter rule structure */
4848struct npf_rule {
4949 sys_snode_t node ;
50- enum net_verdict result ; /*< result if all tests pass */
51- uint32_t nb_tests ; /*< number of tests in this rule */
52- struct npf_test * tests []; /*< pointers to @ref npf_test instances */
50+ enum net_verdict result ; /** < result if all tests pass */
51+ uint32_t nb_tests ; /** < number of tests for this rule */
52+ struct npf_test * tests []; /** < pointers to @ref npf_test instances */
5353};
5454
5555/** @brief Default rule list termination for accepting a packet */
@@ -310,6 +310,7 @@ struct npf_test_eth_addr {
310310 struct npf_test test ;
311311 unsigned int nb_addresses ;
312312 struct net_eth_addr * addresses ;
313+ struct net_eth_addr mask ;
313314};
314315
315316extern npf_test_fn_t npf_eth_src_addr_match ;
@@ -333,6 +334,7 @@ extern npf_test_fn_t npf_eth_dst_addr_unmatch;
333334 .addresses = (_addr_array), \
334335 .nb_addresses = ARRAY_SIZE(_addr_array), \
335336 .test.fn = npf_eth_src_addr_match, \
337+ .mask.addr = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }, \
336338 }
337339
338340/**
@@ -349,6 +351,7 @@ extern npf_test_fn_t npf_eth_dst_addr_unmatch;
349351 .addresses = (_addr_array), \
350352 .nb_addresses = ARRAY_SIZE(_addr_array), \
351353 .test.fn = npf_eth_src_addr_unmatch, \
354+ .mask.addr = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }, \
352355 }
353356
354357/**
@@ -365,6 +368,7 @@ extern npf_test_fn_t npf_eth_dst_addr_unmatch;
365368 .addresses = (_addr_array), \
366369 .nb_addresses = ARRAY_SIZE(_addr_array), \
367370 .test.fn = npf_eth_dst_addr_match, \
371+ .mask.addr = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }, \
368372 }
369373
370374/**
@@ -381,6 +385,43 @@ extern npf_test_fn_t npf_eth_dst_addr_unmatch;
381385 .addresses = (_addr_array), \
382386 .nb_addresses = ARRAY_SIZE(_addr_array), \
383387 .test.fn = npf_eth_dst_addr_unmatch, \
388+ .mask.addr = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }, \
389+ }
390+
391+ /**
392+ * @brief Statically define a "source address match with mask" packet filter condition
393+ *
394+ * This tests if the packet source address matches any of the Ethernet
395+ * addresses contained in the provided set after applying specified mask.
396+ *
397+ * @param _name Name of the condition
398+ * @param _addr_array Array of <tt>struct net_eth_addr</tt> items to test against
399+ * @param ... up to 6 mask bytes
400+ */
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, \
407+ }
408+
409+ /**
410+ * @brief Statically define a "destination address match with mask" packet filter condition
411+ *
412+ * This tests if the packet destination address matches any of the Ethernet
413+ * addresses contained in the provided set after applying specified mask.
414+ *
415+ * @param _name Name of the condition
416+ * @param _addr_array Array of <tt>struct net_eth_addr</tt> items to test against
417+ * @param ... up to 6 mask bytes
418+ */
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, \
384425 }
385426
386427/** @cond INTERNAL_HIDDEN */
0 commit comments