(netdev) 엔트리 후크를 사용하기 위해 체인을 선언할 때 장치 이름 변수를 어떻게 사용합니까?

(netdev) 엔트리 후크를 사용하기 위해 체인을 선언할 때 장치 이름 변수를 어떻게 사용합니까?

netdev필터 테이블 후크 의 경우 ingress장치 이름을 변수에 저장하고 싶지만 올바른 구문을 알 수 없습니다.

작동 방식은 다음과 같습니다.

table netdev filter {
    chain ingress {
        type filter hook ingress device ens33 priority -500;

        # ...
    }
}

...하지만 대신 변수를 사용하고 싶습니다 ens33.

type filter hook ingress device ens33 priority -500;

다음 명령을 사용하면 오류가 발생합니다.

define extif = ens33

table netdev filter {
    chain ingress {
        type filter hook ingress device $extif priority -500;

        # ...
    }
}

오류는 다음과 같습니다.

Error: syntax error, unexpected '$', expecting string or quoted string or string with a trailing asterisk

이제 나는 그것이 in과 유사하기를 바라고 노력했지만 ens*잘못된 장치 이름을 제공할 때 발생한 오류로 변경되었습니다.ens+iptables

Error: Could not process rule: No such file or directory
        chain ingress {
              ^^^^^^^

같은 인용문은 나에게도 효과가 없습니다.문서또한 그것이 작동하도록 하는 단서도 없습니다.

device섹션 에서 매개변수 로 사용할 수 있도록 외부 인터페이스의 이름을 변수에 어떻게 넣을 수 있습니까 type filter hook ...?


커널은 5.8이고 시스템은 Ubuntu 20.04입니다. nftables로 보고되었습니다 v0.9.3 (Topsy).

답변1

아 이런 기능이 추가됐구나이번에 제출하세요그 이후에만 이용 가능nftables 0.9.7. nftables 0.9.8로 테스트할 때 규칙 세트는 그대로 작동합니다.

src: 플로우테이블 및 체인 장치에서 변수 사용을 허용합니다.

이 패치는 다음에 대한 지원을 추가합니다.체인에 있는 장치의 변수 사용 흐름 가능한 정의, 예:

define if_main = lo

table netdev filter1 {
   chain Main_Ingress1 {
       type filter hook ingress device $if_main priority -500; policy accept;
   }
}

서명자: Pablo Nela Ayuso[이메일 보호됨]


netdev 제품군 체인은 또는많은 종류의(커널 5.5 및 nftables 0.9.3부터 시작) 인터페이스는 체인 정의 이전에 모두 존재해야 합니다. 와일드카드 문자는 사용할 수 없습니다.

이것여러 장치체인 구문은 약간 다릅니다.

table netdev filter {
    chain ingress {
        type filter hook ingress devices = { ens33, ens34 } priority -500;

        # ...
    }
}

또는nftables>= 0.9.7:

define extifs = { ens33, ens34 }

table netdev filter {
    chain ingress {
        type filter hook ingress devices = $extifs priority -500;

        # ...
    }
}

이전 기존 구문을 사용하여 하나의 인터페이스(예: { ens33 })만 다시 표시됩니다.

관련 정보