nftablesで指定されたICMP型セットの宣言と使用

nftablesで指定されたICMP型セットの宣言と使用

unamed set以下は、現在のICMPタイプの使用方法の実際の例です。

#!/usr/sbin/nft -f

add table filter_4

add chain filter_4 icmp_out_4 {
    comment "Output ICMPv4 traffic"
}

define response_icmp_4 = {
    0, # Echo Reply
    3, # Destination Unreachable
    10, # Router Solicitation
    11, # Time Exceeded
    12, # Parameter Problem
    14 # Timestamp Reply
}

# Block ICMP response from localhost
add rule filter_4 icmp_out_4 icmp type $response_icmp_4 drop

私がしたいのは、それを名前付きセットunamed setに変換することです。失敗した試みは次のとおりです。response_icmp_4

# Declare named set
add set filter_4 response_icmp_4 { type inet_service }

# Add ICMP type elements
add element filter_4 response_icmp_4 {
    0, # Echo Reply
    3, # Destination Unreachable
    10, # Router Solicitation
    11, # Time Exceeded
    12, # Parameter Problem
    14 # Timestamp Reply
}

コレクションの作成は機能しますが、ルール処理中に拒否されます。

# Block ICMP response from localhost
add rule filter_4 icmp_out_4 icmp type @response_icmp_4 drop

次のエラー出力があります。

エラー:データ型が一致しません。 ICMPタイプが必要で、式はインターネットネットワークサービスタイプです。

エラーは自明ですが、質問はtype何を指定する必要がありますか?type inet_serviceうまくいかないからです。

~によると文書有効なtype式は次のとおりです。ipv4_addr, ipv6_addr, ether_addr, inet_proto, inet_service, mark

自動的に派生したデータ型を指定することも可能ですtypeofが、これは正しく機能しません。たとえば、次のようになります。

add set filter_4 response_icmp_4 { typeof vlan id }

次のようなエラーは何ですか?

エラー:データ型の不一致、予想されるICMPタイプ、式タイプが整数です。

ICMP typeこれは整数なので奇妙なエラーです。

これについて説明する文書が見つからないので、リンクしてください。

ベストアンサー1

名前付きセット宣言は、比較される型と一致する必要があります。 ICMPタイプはinetサービスではありません。

# nft describe inet_service
datatype inet_service (internet network service) (basetype integer), 16 bits

これは港を意味します。たとえば、以下と互換性があります。

# nft describe udp dport
payload expression, datatype inet_service (internet network service) (basetype integer), 16 bits

したがって、ルールを追加するときnftables文句を言う:

Error: datatype mismatch, expected ICMP type, expression has type internet network service

ICMPタイプを見つける方法は、ルール(ペイロード表現/タイプ)で次のとおりですicmp type

# nft describe icmp type
payload expression, datatype icmp_type (ICMP type) (basetype integer), 8 bits

pre-defined symbolic constants (in decimal):
    echo-reply                                         0
    destination-unreachable                            3
[...]

(データタイプ/タイプ)の結果は次のとおりですicmp_type

# nft describe icmp_type
datatype icmp_type (ICMP type) (basetype integer), 8 bits

pre-defined symbolic constants (in decimal):
    echo-reply                                         0
    destination-unreachable                            3
[...]

これ:

add set filter_4 response_icmp_4 { type inet_service }

次に交換する必要があります。

add set filter_4 response_icmp_4 { type icmp_type; }

typeまたは、次のものを使用する代わりにtypeof(通常はルールセットで使用されているものと一致するため、理解するのが簡単で、上記のように直接使用してnft describe同等の項目を見つけることもできますtype):

add set filter_4 response_icmp_4 { typeof icmp type; }

おすすめ記事