#include <stdlib.h>
#include <xtables.h>
#include <linux/netfilter_ipv6/ip6t_mh.h>
+#include <linux/netfilter_ipv6/ip6_tables.h>
enum {
O_MH_TYPE = 0,
printf("%s", name);
}
+static bool skip_types_match(uint8_t min, uint8_t max, bool inv)
+{
+ return min == 0 && max == UINT8_MAX && !inv;
+}
+
static void print_types(uint8_t min, uint8_t max, int invert, int numeric)
{
const char *inv = invert ? "!" : "";
- if (min != 0 || max != 0xFF || invert) {
+ if (!skip_types_match(min, max, invert)) {
printf(" ");
if (min == max) {
printf("%s", inv);
static void mh_save(const void *ip, const struct xt_entry_match *match)
{
const struct ip6t_mh *mhinfo = (struct ip6t_mh *)match->data;
+ bool inv_type = mhinfo->invflags & IP6T_MH_INV_TYPE;
- if (mhinfo->types[0] == 0 && mhinfo->types[1] == 0xFF)
+ if (skip_types_match(mhinfo->types[0], mhinfo->types[1], inv_type))
return;
- if (mhinfo->invflags & IP6T_MH_INV_TYPE)
+ if (inv_type)
printf(" !");
if (mhinfo->types[0] != mhinfo->types[1])
const struct xt_xlate_mt_params *params)
{
const struct ip6t_mh *mhinfo = (struct ip6t_mh *)params->match->data;
+ bool inv_type = mhinfo->invflags & IP6T_MH_INV_TYPE;
+ uint8_t proto = ((const struct ip6t_ip6 *)params->ip)->proto;
- if (mhinfo->types[0] == 0 && mhinfo->types[1] == 0xff)
+ if (skip_types_match(mhinfo->types[0], mhinfo->types[1], inv_type)) {
+ if (proto != IPPROTO_MH)
+ xt_xlate_add(xl, "exthdr mh exists");
return 1;
+ }
if (mhinfo->types[0] != mhinfo->types[1])
xt_xlate_add(xl, "mh type %s%u-%u",
-p mobility-header -m mh ! --mh-type 4;=;OK
-p mobility-header -m mh --mh-type 4:123;=;OK
-p mobility-header -m mh --mh-type :;-p mobility-header -m mh;OK
--p mobility-header -m mh ! --mh-type :;-p mobility-header -m mh;OK
+-p mobility-header -m mh ! --mh-type :;-p mobility-header -m mh ! --mh-type 0:255;OK
-p mobility-header -m mh --mh-type :3;-p mobility-header -m mh --mh-type 0:3;OK
-p mobility-header -m mh --mh-type 3:;-p mobility-header -m mh --mh-type 3:255;OK
-p mobility-header -m mh --mh-type 3:3;-p mobility-header -m mh --mh-type 3;OK
nft 'add rule ip6 filter INPUT meta l4proto mobility-header counter accept'
ip6tables-translate -A INPUT -m mh --mh-type 0:255 -j ACCEPT
-nft 'add rule ip6 filter INPUT counter accept'
+nft 'add rule ip6 filter INPUT exthdr mh exists counter accept'
ip6tables-translate -A INPUT -p mh ! --mh-type 0:255 -j ACCEPT
-nft 'add rule ip6 filter INPUT meta l4proto mobility-header counter accept'
+nft 'add rule ip6 filter INPUT meta l4proto mobility-header mh type != 0-255 counter accept'