How to block incoming IPv6 fragments?How can one distinguish the host and the port in an IPv6 URL?Why can't IPv6 send broadcasts?Can I block all IPv6 traffic if I'm not using it/planning to use it?How to block all incoming request through one network interface?How does IPv6 subnetting work and how does it differ from IPv4 subnetting?ADSL router happily accepts IPv6 packets of 2K in sizePrefer IPv4 incoming connections over IPv6IPv6 - Allow incoming ICMP echo requestsIPv6 and /64 block allocationhow to block incoming DHCP DISCOVERY messages

Survey Confirmation - Emphasize the question or the answer?

Is balancing necessary on a full-wheel change?

Pigeonhole Principle Problem

Unexpected email from Yorkshire Bank

Was the ancestor of SCSI, the SASI protocol, nothing more than a draft?

Entropy as a function of temperature: is temperature well defined?

Disabling Resource Governor in SQL Server

If an enemy is just below a 10-foot-high ceiling, are they in melee range of a creature on the ground?

Is it cheaper to drop cargo than to land it?

How to reply this mail from potential PhD professor?

Can I use 1000v rectifier diodes instead of 600v rectifier diodes?

Does hiding behind 5-ft-wide cover give full cover?

Meaning of "individuandum"

What are the spoon bit of a spoon and fork bit of a fork called?

What is the limiting factor for a CAN bus to exceed 1Mbps bandwidth?

Airbnb - host wants to reduce rooms, can we get refund?

How long can a 35mm film be used/stored before it starts to lose its quality after expiry?

Can fracking help reduce CO2?

Write to EXCEL from SQL DB using VBA script

Why was Germany not as successful as other Europeans in establishing overseas colonies?

How to efficiently calculate prefix sum of frequencies of characters in a string?

A non-technological, repeating, phenomenon in the sky, holding its position in the sky for hours

How to back up a running Linode server?

Hang 20lb projector screen on Hardieplank



How to block incoming IPv6 fragments?


How can one distinguish the host and the port in an IPv6 URL?Why can't IPv6 send broadcasts?Can I block all IPv6 traffic if I'm not using it/planning to use it?How to block all incoming request through one network interface?How does IPv6 subnetting work and how does it differ from IPv4 subnetting?ADSL router happily accepts IPv6 packets of 2K in sizePrefer IPv4 incoming connections over IPv6IPv6 - Allow incoming ICMP echo requestsIPv6 and /64 block allocationhow to block incoming DHCP DISCOVERY messages






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








1















I have an issue with my firewall configuration.
I would like to block all IPv6 fragmented packets in a sopecific interface. So, I tried:



# ip6tables -A INPUT -d <ipv6_address> -i eth0 -m ipv6header --header ipv6-frag --soft -j DROP


But IPv6 fragmented traffic keeps going in.



I have also found this link: https://www.secfu.net/2015/03/25/how-to-block-incoming-ipv6-fragments-in-latest-red-hat-releases/
that explains that ipv6-frag or frag do not block the ipv6 fragmented traffic in the latest CentOS, because after bug id 1011214 (kernel-2.6.32-437.el6) netfilter started processing the reassembled packet instead of the fragments, like IPv4 does. The same article suggests to use nftables which would look like as follows:



table ip6 filter 
chain preroute500
type filter hook prerouting priority -500; policy accept;
ip6 nexthdr ipv6-frag counter packets 2 bytes 2104




How can I do something like that using ip6tables?



# cat /etc/system-release
CentOS Linux release 7.5.1804 (Core)

# uname -r
5.0.8-1.el7.elrepo.x86_64









share|improve this question

















  • 1





    You can't do it in ip6tables, as the document you linked to explained. Why do you want to do this at all? Perhaps there is some alternate way to accomplish your real goal.

    – Michael Hampton
    Apr 22 at 16:40












  • My real goal is to test the firewall rule with protocol ipv6-frag|frag|44 protocol. I have created with scapy some fragmented IPv6 packets, however no matter which rule I add, they are not dropped.

    – belabrinel
    Apr 23 at 10:45

















1















I have an issue with my firewall configuration.
I would like to block all IPv6 fragmented packets in a sopecific interface. So, I tried:



# ip6tables -A INPUT -d <ipv6_address> -i eth0 -m ipv6header --header ipv6-frag --soft -j DROP


But IPv6 fragmented traffic keeps going in.



I have also found this link: https://www.secfu.net/2015/03/25/how-to-block-incoming-ipv6-fragments-in-latest-red-hat-releases/
that explains that ipv6-frag or frag do not block the ipv6 fragmented traffic in the latest CentOS, because after bug id 1011214 (kernel-2.6.32-437.el6) netfilter started processing the reassembled packet instead of the fragments, like IPv4 does. The same article suggests to use nftables which would look like as follows:



table ip6 filter 
chain preroute500
type filter hook prerouting priority -500; policy accept;
ip6 nexthdr ipv6-frag counter packets 2 bytes 2104




How can I do something like that using ip6tables?



# cat /etc/system-release
CentOS Linux release 7.5.1804 (Core)

# uname -r
5.0.8-1.el7.elrepo.x86_64









share|improve this question

















  • 1





    You can't do it in ip6tables, as the document you linked to explained. Why do you want to do this at all? Perhaps there is some alternate way to accomplish your real goal.

    – Michael Hampton
    Apr 22 at 16:40












  • My real goal is to test the firewall rule with protocol ipv6-frag|frag|44 protocol. I have created with scapy some fragmented IPv6 packets, however no matter which rule I add, they are not dropped.

    – belabrinel
    Apr 23 at 10:45













1












1








1


1






I have an issue with my firewall configuration.
I would like to block all IPv6 fragmented packets in a sopecific interface. So, I tried:



# ip6tables -A INPUT -d <ipv6_address> -i eth0 -m ipv6header --header ipv6-frag --soft -j DROP


But IPv6 fragmented traffic keeps going in.



I have also found this link: https://www.secfu.net/2015/03/25/how-to-block-incoming-ipv6-fragments-in-latest-red-hat-releases/
that explains that ipv6-frag or frag do not block the ipv6 fragmented traffic in the latest CentOS, because after bug id 1011214 (kernel-2.6.32-437.el6) netfilter started processing the reassembled packet instead of the fragments, like IPv4 does. The same article suggests to use nftables which would look like as follows:



table ip6 filter 
chain preroute500
type filter hook prerouting priority -500; policy accept;
ip6 nexthdr ipv6-frag counter packets 2 bytes 2104




How can I do something like that using ip6tables?



# cat /etc/system-release
CentOS Linux release 7.5.1804 (Core)

# uname -r
5.0.8-1.el7.elrepo.x86_64









share|improve this question














I have an issue with my firewall configuration.
I would like to block all IPv6 fragmented packets in a sopecific interface. So, I tried:



# ip6tables -A INPUT -d <ipv6_address> -i eth0 -m ipv6header --header ipv6-frag --soft -j DROP


But IPv6 fragmented traffic keeps going in.



I have also found this link: https://www.secfu.net/2015/03/25/how-to-block-incoming-ipv6-fragments-in-latest-red-hat-releases/
that explains that ipv6-frag or frag do not block the ipv6 fragmented traffic in the latest CentOS, because after bug id 1011214 (kernel-2.6.32-437.el6) netfilter started processing the reassembled packet instead of the fragments, like IPv4 does. The same article suggests to use nftables which would look like as follows:



table ip6 filter 
chain preroute500
type filter hook prerouting priority -500; policy accept;
ip6 nexthdr ipv6-frag counter packets 2 bytes 2104




How can I do something like that using ip6tables?



# cat /etc/system-release
CentOS Linux release 7.5.1804 (Core)

# uname -r
5.0.8-1.el7.elrepo.x86_64






firewall ipv6 fragmentation






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Apr 22 at 15:41









belabrinelbelabrinel

154




154







  • 1





    You can't do it in ip6tables, as the document you linked to explained. Why do you want to do this at all? Perhaps there is some alternate way to accomplish your real goal.

    – Michael Hampton
    Apr 22 at 16:40












  • My real goal is to test the firewall rule with protocol ipv6-frag|frag|44 protocol. I have created with scapy some fragmented IPv6 packets, however no matter which rule I add, they are not dropped.

    – belabrinel
    Apr 23 at 10:45












  • 1





    You can't do it in ip6tables, as the document you linked to explained. Why do you want to do this at all? Perhaps there is some alternate way to accomplish your real goal.

    – Michael Hampton
    Apr 22 at 16:40












  • My real goal is to test the firewall rule with protocol ipv6-frag|frag|44 protocol. I have created with scapy some fragmented IPv6 packets, however no matter which rule I add, they are not dropped.

    – belabrinel
    Apr 23 at 10:45







1




1





You can't do it in ip6tables, as the document you linked to explained. Why do you want to do this at all? Perhaps there is some alternate way to accomplish your real goal.

– Michael Hampton
Apr 22 at 16:40






You can't do it in ip6tables, as the document you linked to explained. Why do you want to do this at all? Perhaps there is some alternate way to accomplish your real goal.

– Michael Hampton
Apr 22 at 16:40














My real goal is to test the firewall rule with protocol ipv6-frag|frag|44 protocol. I have created with scapy some fragmented IPv6 packets, however no matter which rule I add, they are not dropped.

– belabrinel
Apr 23 at 10:45





My real goal is to test the firewall rule with protocol ipv6-frag|frag|44 protocol. I have created with scapy some fragmented IPv6 packets, however no matter which rule I add, they are not dropped.

– belabrinel
Apr 23 at 10:45










1 Answer
1






active

oldest

votes


















1














As has been said, you should be sure that blocking fragments is really your goal, and not a method you think is best for your goal, while better methods would exist. Anyway, for what it's worth you must:




  • use a recent enough kernel. The feature was added in kernel 4.16. CentOS uses 3.10. While many features are backported (starting with nftables which isn't available on a vanilla 3.10 kernel but is on RHEL/CentOS's 3.10), this feature wasn't backported as of latest CentOS 7.6's kernel. Since you're using an "elrepo" 5.0.8 kernel, the feature is present. Here's the feature description and why it exists (mostly for routing, or at least non-stateful/non-NAT firewall routing situations):




    netfilter: nf_defrag:



    Skip defrag if NOTRACK is set conntrack defrag
    is needed only if some module like CONNTRACK or NAT explicitly
    requests it. For plain forwarding scenarios, defrag is not needed and
    can be skipped if NOTRACK is set in a rule.



    Since conntrack defrag is currently higher priority than raw table,
    setting NOTRACK is not sufficient. We need to move raw to a higher
    priority for iptables only.



    This is achieved by introducing a module parameter "raw_before_defrag"
    which allows to change the priority of raw table to place it before
    defrag. By default, the parameter is disabled and the priority of raw
    table is NF_IP_PRI_RAW to support legacy behavior. If the module
    parameter is enabled, then the priority of the raw table is set to
    NF_IP_PRI_RAW_BEFORE_DEFRAG.





  • (if needed remove existing raw ip6tables rules, unload and) load the ip6table_raw module with the parameter raw_before_defrag=1, so the raw's hook (in PREROUTING) switchs from prio -300 to -450, before defrag's -400.



    modprobe ip6table_raw raw_before_defrag=1


    which should get a kernel message like ip6table_raw: Enabling raw table before defrag



Now in the raw table, and probably making sense only in PREROUTING, ip6tables will be able to see fragments. It can filter them there, or choose to skip conntrack (iptables -t raw -A PREROUTING ... -j CT --notrack), which as explained in the feature patch, will skip defragmentation too, allowing other chains to handle them (of course not including nat table's chains nor any other conntrack related feature).




Note that to witness the problem described in a test network namespace, one must first artificially enable conntrack operations for conntrack's dependency with defrag, which isn't activated until first needed. Here's a network namespace example:



ip netns add sender
ip netns add receiver
ip -n sender link add veth0 address 02:00:00:00:00:01 type veth peer netns receiver name veth0 address 02:00:00:00:00:02
ip -n sender link set veth0 up
ip -n receiver link set veth0 up


This works:



# ip netns exec sender ping6 -s 4000 fe80::ff:fe00:2%veth0
PING fe80::ff:fe00:2%veth0(fe80::ff:fe00:2%veth0) 4000 data bytes
4008 bytes from fe80::ff:fe00:2%veth0: icmp_seq=1 ttl=64 time=0.069 ms
^C


After this, it won't work anymore:



ip netns exec receiver ip6tables -A INPUT -m ipv6header --header ipv6-frag --soft -j DROP


Once conntrack is activated in the network namespace with those commands apparently resulting in a no-op:



ip netns exec receiver ip6tables -A INPUT -m conntrack --ctstate ESTABLISHED
ip netns exec receiver ip6tables -D INPUT -m conntrack --ctstate ESTABLISHED


the ipv6 defragmentation is also activated. Now the previous ping will always work, because the rule in INPUT only sees defragmented packets.



With the previously (re)loaded ip6table_raw module with parameter raw_before_defrag=1, this will restore fragmented ping's blocking:



ip netns exec receiver ip6tables -t raw -A PREROUTING -m ipv6header --header ipv6-frag --soft -j DROP


Alternatively, interesting packets can be marked as notrack, thus exempting them of conntrack, thus not receiving defrag treatement either, allowing them to be filtered again with the rule in the filter/INPUT chain. So instead of the previous raw rule, this would also block the ping packets (3 of them per ping), but this time again in the filter/INPUT chain:



ip netns exec receiver ip6tables -t raw -A PREROUTING -m ipv6header --header ipv6-frag --soft -j CT --notrack


This is an example only which doesn't make much sense.






share|improve this answer

























  • added that a packet, including fragments, can also be marked as notrack for further (non stateful) processing after the raw table.

    – A.B
    Apr 23 at 18:17












Your Answer








StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "2"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f964072%2fhow-to-block-incoming-ipv6-fragments%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














As has been said, you should be sure that blocking fragments is really your goal, and not a method you think is best for your goal, while better methods would exist. Anyway, for what it's worth you must:




  • use a recent enough kernel. The feature was added in kernel 4.16. CentOS uses 3.10. While many features are backported (starting with nftables which isn't available on a vanilla 3.10 kernel but is on RHEL/CentOS's 3.10), this feature wasn't backported as of latest CentOS 7.6's kernel. Since you're using an "elrepo" 5.0.8 kernel, the feature is present. Here's the feature description and why it exists (mostly for routing, or at least non-stateful/non-NAT firewall routing situations):




    netfilter: nf_defrag:



    Skip defrag if NOTRACK is set conntrack defrag
    is needed only if some module like CONNTRACK or NAT explicitly
    requests it. For plain forwarding scenarios, defrag is not needed and
    can be skipped if NOTRACK is set in a rule.



    Since conntrack defrag is currently higher priority than raw table,
    setting NOTRACK is not sufficient. We need to move raw to a higher
    priority for iptables only.



    This is achieved by introducing a module parameter "raw_before_defrag"
    which allows to change the priority of raw table to place it before
    defrag. By default, the parameter is disabled and the priority of raw
    table is NF_IP_PRI_RAW to support legacy behavior. If the module
    parameter is enabled, then the priority of the raw table is set to
    NF_IP_PRI_RAW_BEFORE_DEFRAG.





  • (if needed remove existing raw ip6tables rules, unload and) load the ip6table_raw module with the parameter raw_before_defrag=1, so the raw's hook (in PREROUTING) switchs from prio -300 to -450, before defrag's -400.



    modprobe ip6table_raw raw_before_defrag=1


    which should get a kernel message like ip6table_raw: Enabling raw table before defrag



Now in the raw table, and probably making sense only in PREROUTING, ip6tables will be able to see fragments. It can filter them there, or choose to skip conntrack (iptables -t raw -A PREROUTING ... -j CT --notrack), which as explained in the feature patch, will skip defragmentation too, allowing other chains to handle them (of course not including nat table's chains nor any other conntrack related feature).




Note that to witness the problem described in a test network namespace, one must first artificially enable conntrack operations for conntrack's dependency with defrag, which isn't activated until first needed. Here's a network namespace example:



ip netns add sender
ip netns add receiver
ip -n sender link add veth0 address 02:00:00:00:00:01 type veth peer netns receiver name veth0 address 02:00:00:00:00:02
ip -n sender link set veth0 up
ip -n receiver link set veth0 up


This works:



# ip netns exec sender ping6 -s 4000 fe80::ff:fe00:2%veth0
PING fe80::ff:fe00:2%veth0(fe80::ff:fe00:2%veth0) 4000 data bytes
4008 bytes from fe80::ff:fe00:2%veth0: icmp_seq=1 ttl=64 time=0.069 ms
^C


After this, it won't work anymore:



ip netns exec receiver ip6tables -A INPUT -m ipv6header --header ipv6-frag --soft -j DROP


Once conntrack is activated in the network namespace with those commands apparently resulting in a no-op:



ip netns exec receiver ip6tables -A INPUT -m conntrack --ctstate ESTABLISHED
ip netns exec receiver ip6tables -D INPUT -m conntrack --ctstate ESTABLISHED


the ipv6 defragmentation is also activated. Now the previous ping will always work, because the rule in INPUT only sees defragmented packets.



With the previously (re)loaded ip6table_raw module with parameter raw_before_defrag=1, this will restore fragmented ping's blocking:



ip netns exec receiver ip6tables -t raw -A PREROUTING -m ipv6header --header ipv6-frag --soft -j DROP


Alternatively, interesting packets can be marked as notrack, thus exempting them of conntrack, thus not receiving defrag treatement either, allowing them to be filtered again with the rule in the filter/INPUT chain. So instead of the previous raw rule, this would also block the ping packets (3 of them per ping), but this time again in the filter/INPUT chain:



ip netns exec receiver ip6tables -t raw -A PREROUTING -m ipv6header --header ipv6-frag --soft -j CT --notrack


This is an example only which doesn't make much sense.






share|improve this answer

























  • added that a packet, including fragments, can also be marked as notrack for further (non stateful) processing after the raw table.

    – A.B
    Apr 23 at 18:17
















1














As has been said, you should be sure that blocking fragments is really your goal, and not a method you think is best for your goal, while better methods would exist. Anyway, for what it's worth you must:




  • use a recent enough kernel. The feature was added in kernel 4.16. CentOS uses 3.10. While many features are backported (starting with nftables which isn't available on a vanilla 3.10 kernel but is on RHEL/CentOS's 3.10), this feature wasn't backported as of latest CentOS 7.6's kernel. Since you're using an "elrepo" 5.0.8 kernel, the feature is present. Here's the feature description and why it exists (mostly for routing, or at least non-stateful/non-NAT firewall routing situations):




    netfilter: nf_defrag:



    Skip defrag if NOTRACK is set conntrack defrag
    is needed only if some module like CONNTRACK or NAT explicitly
    requests it. For plain forwarding scenarios, defrag is not needed and
    can be skipped if NOTRACK is set in a rule.



    Since conntrack defrag is currently higher priority than raw table,
    setting NOTRACK is not sufficient. We need to move raw to a higher
    priority for iptables only.



    This is achieved by introducing a module parameter "raw_before_defrag"
    which allows to change the priority of raw table to place it before
    defrag. By default, the parameter is disabled and the priority of raw
    table is NF_IP_PRI_RAW to support legacy behavior. If the module
    parameter is enabled, then the priority of the raw table is set to
    NF_IP_PRI_RAW_BEFORE_DEFRAG.





  • (if needed remove existing raw ip6tables rules, unload and) load the ip6table_raw module with the parameter raw_before_defrag=1, so the raw's hook (in PREROUTING) switchs from prio -300 to -450, before defrag's -400.



    modprobe ip6table_raw raw_before_defrag=1


    which should get a kernel message like ip6table_raw: Enabling raw table before defrag



Now in the raw table, and probably making sense only in PREROUTING, ip6tables will be able to see fragments. It can filter them there, or choose to skip conntrack (iptables -t raw -A PREROUTING ... -j CT --notrack), which as explained in the feature patch, will skip defragmentation too, allowing other chains to handle them (of course not including nat table's chains nor any other conntrack related feature).




Note that to witness the problem described in a test network namespace, one must first artificially enable conntrack operations for conntrack's dependency with defrag, which isn't activated until first needed. Here's a network namespace example:



ip netns add sender
ip netns add receiver
ip -n sender link add veth0 address 02:00:00:00:00:01 type veth peer netns receiver name veth0 address 02:00:00:00:00:02
ip -n sender link set veth0 up
ip -n receiver link set veth0 up


This works:



# ip netns exec sender ping6 -s 4000 fe80::ff:fe00:2%veth0
PING fe80::ff:fe00:2%veth0(fe80::ff:fe00:2%veth0) 4000 data bytes
4008 bytes from fe80::ff:fe00:2%veth0: icmp_seq=1 ttl=64 time=0.069 ms
^C


After this, it won't work anymore:



ip netns exec receiver ip6tables -A INPUT -m ipv6header --header ipv6-frag --soft -j DROP


Once conntrack is activated in the network namespace with those commands apparently resulting in a no-op:



ip netns exec receiver ip6tables -A INPUT -m conntrack --ctstate ESTABLISHED
ip netns exec receiver ip6tables -D INPUT -m conntrack --ctstate ESTABLISHED


the ipv6 defragmentation is also activated. Now the previous ping will always work, because the rule in INPUT only sees defragmented packets.



With the previously (re)loaded ip6table_raw module with parameter raw_before_defrag=1, this will restore fragmented ping's blocking:



ip netns exec receiver ip6tables -t raw -A PREROUTING -m ipv6header --header ipv6-frag --soft -j DROP


Alternatively, interesting packets can be marked as notrack, thus exempting them of conntrack, thus not receiving defrag treatement either, allowing them to be filtered again with the rule in the filter/INPUT chain. So instead of the previous raw rule, this would also block the ping packets (3 of them per ping), but this time again in the filter/INPUT chain:



ip netns exec receiver ip6tables -t raw -A PREROUTING -m ipv6header --header ipv6-frag --soft -j CT --notrack


This is an example only which doesn't make much sense.






share|improve this answer

























  • added that a packet, including fragments, can also be marked as notrack for further (non stateful) processing after the raw table.

    – A.B
    Apr 23 at 18:17














1












1








1







As has been said, you should be sure that blocking fragments is really your goal, and not a method you think is best for your goal, while better methods would exist. Anyway, for what it's worth you must:




  • use a recent enough kernel. The feature was added in kernel 4.16. CentOS uses 3.10. While many features are backported (starting with nftables which isn't available on a vanilla 3.10 kernel but is on RHEL/CentOS's 3.10), this feature wasn't backported as of latest CentOS 7.6's kernel. Since you're using an "elrepo" 5.0.8 kernel, the feature is present. Here's the feature description and why it exists (mostly for routing, or at least non-stateful/non-NAT firewall routing situations):




    netfilter: nf_defrag:



    Skip defrag if NOTRACK is set conntrack defrag
    is needed only if some module like CONNTRACK or NAT explicitly
    requests it. For plain forwarding scenarios, defrag is not needed and
    can be skipped if NOTRACK is set in a rule.



    Since conntrack defrag is currently higher priority than raw table,
    setting NOTRACK is not sufficient. We need to move raw to a higher
    priority for iptables only.



    This is achieved by introducing a module parameter "raw_before_defrag"
    which allows to change the priority of raw table to place it before
    defrag. By default, the parameter is disabled and the priority of raw
    table is NF_IP_PRI_RAW to support legacy behavior. If the module
    parameter is enabled, then the priority of the raw table is set to
    NF_IP_PRI_RAW_BEFORE_DEFRAG.





  • (if needed remove existing raw ip6tables rules, unload and) load the ip6table_raw module with the parameter raw_before_defrag=1, so the raw's hook (in PREROUTING) switchs from prio -300 to -450, before defrag's -400.



    modprobe ip6table_raw raw_before_defrag=1


    which should get a kernel message like ip6table_raw: Enabling raw table before defrag



Now in the raw table, and probably making sense only in PREROUTING, ip6tables will be able to see fragments. It can filter them there, or choose to skip conntrack (iptables -t raw -A PREROUTING ... -j CT --notrack), which as explained in the feature patch, will skip defragmentation too, allowing other chains to handle them (of course not including nat table's chains nor any other conntrack related feature).




Note that to witness the problem described in a test network namespace, one must first artificially enable conntrack operations for conntrack's dependency with defrag, which isn't activated until first needed. Here's a network namespace example:



ip netns add sender
ip netns add receiver
ip -n sender link add veth0 address 02:00:00:00:00:01 type veth peer netns receiver name veth0 address 02:00:00:00:00:02
ip -n sender link set veth0 up
ip -n receiver link set veth0 up


This works:



# ip netns exec sender ping6 -s 4000 fe80::ff:fe00:2%veth0
PING fe80::ff:fe00:2%veth0(fe80::ff:fe00:2%veth0) 4000 data bytes
4008 bytes from fe80::ff:fe00:2%veth0: icmp_seq=1 ttl=64 time=0.069 ms
^C


After this, it won't work anymore:



ip netns exec receiver ip6tables -A INPUT -m ipv6header --header ipv6-frag --soft -j DROP


Once conntrack is activated in the network namespace with those commands apparently resulting in a no-op:



ip netns exec receiver ip6tables -A INPUT -m conntrack --ctstate ESTABLISHED
ip netns exec receiver ip6tables -D INPUT -m conntrack --ctstate ESTABLISHED


the ipv6 defragmentation is also activated. Now the previous ping will always work, because the rule in INPUT only sees defragmented packets.



With the previously (re)loaded ip6table_raw module with parameter raw_before_defrag=1, this will restore fragmented ping's blocking:



ip netns exec receiver ip6tables -t raw -A PREROUTING -m ipv6header --header ipv6-frag --soft -j DROP


Alternatively, interesting packets can be marked as notrack, thus exempting them of conntrack, thus not receiving defrag treatement either, allowing them to be filtered again with the rule in the filter/INPUT chain. So instead of the previous raw rule, this would also block the ping packets (3 of them per ping), but this time again in the filter/INPUT chain:



ip netns exec receiver ip6tables -t raw -A PREROUTING -m ipv6header --header ipv6-frag --soft -j CT --notrack


This is an example only which doesn't make much sense.






share|improve this answer















As has been said, you should be sure that blocking fragments is really your goal, and not a method you think is best for your goal, while better methods would exist. Anyway, for what it's worth you must:




  • use a recent enough kernel. The feature was added in kernel 4.16. CentOS uses 3.10. While many features are backported (starting with nftables which isn't available on a vanilla 3.10 kernel but is on RHEL/CentOS's 3.10), this feature wasn't backported as of latest CentOS 7.6's kernel. Since you're using an "elrepo" 5.0.8 kernel, the feature is present. Here's the feature description and why it exists (mostly for routing, or at least non-stateful/non-NAT firewall routing situations):




    netfilter: nf_defrag:



    Skip defrag if NOTRACK is set conntrack defrag
    is needed only if some module like CONNTRACK or NAT explicitly
    requests it. For plain forwarding scenarios, defrag is not needed and
    can be skipped if NOTRACK is set in a rule.



    Since conntrack defrag is currently higher priority than raw table,
    setting NOTRACK is not sufficient. We need to move raw to a higher
    priority for iptables only.



    This is achieved by introducing a module parameter "raw_before_defrag"
    which allows to change the priority of raw table to place it before
    defrag. By default, the parameter is disabled and the priority of raw
    table is NF_IP_PRI_RAW to support legacy behavior. If the module
    parameter is enabled, then the priority of the raw table is set to
    NF_IP_PRI_RAW_BEFORE_DEFRAG.





  • (if needed remove existing raw ip6tables rules, unload and) load the ip6table_raw module with the parameter raw_before_defrag=1, so the raw's hook (in PREROUTING) switchs from prio -300 to -450, before defrag's -400.



    modprobe ip6table_raw raw_before_defrag=1


    which should get a kernel message like ip6table_raw: Enabling raw table before defrag



Now in the raw table, and probably making sense only in PREROUTING, ip6tables will be able to see fragments. It can filter them there, or choose to skip conntrack (iptables -t raw -A PREROUTING ... -j CT --notrack), which as explained in the feature patch, will skip defragmentation too, allowing other chains to handle them (of course not including nat table's chains nor any other conntrack related feature).




Note that to witness the problem described in a test network namespace, one must first artificially enable conntrack operations for conntrack's dependency with defrag, which isn't activated until first needed. Here's a network namespace example:



ip netns add sender
ip netns add receiver
ip -n sender link add veth0 address 02:00:00:00:00:01 type veth peer netns receiver name veth0 address 02:00:00:00:00:02
ip -n sender link set veth0 up
ip -n receiver link set veth0 up


This works:



# ip netns exec sender ping6 -s 4000 fe80::ff:fe00:2%veth0
PING fe80::ff:fe00:2%veth0(fe80::ff:fe00:2%veth0) 4000 data bytes
4008 bytes from fe80::ff:fe00:2%veth0: icmp_seq=1 ttl=64 time=0.069 ms
^C


After this, it won't work anymore:



ip netns exec receiver ip6tables -A INPUT -m ipv6header --header ipv6-frag --soft -j DROP


Once conntrack is activated in the network namespace with those commands apparently resulting in a no-op:



ip netns exec receiver ip6tables -A INPUT -m conntrack --ctstate ESTABLISHED
ip netns exec receiver ip6tables -D INPUT -m conntrack --ctstate ESTABLISHED


the ipv6 defragmentation is also activated. Now the previous ping will always work, because the rule in INPUT only sees defragmented packets.



With the previously (re)loaded ip6table_raw module with parameter raw_before_defrag=1, this will restore fragmented ping's blocking:



ip netns exec receiver ip6tables -t raw -A PREROUTING -m ipv6header --header ipv6-frag --soft -j DROP


Alternatively, interesting packets can be marked as notrack, thus exempting them of conntrack, thus not receiving defrag treatement either, allowing them to be filtered again with the rule in the filter/INPUT chain. So instead of the previous raw rule, this would also block the ping packets (3 of them per ping), but this time again in the filter/INPUT chain:



ip netns exec receiver ip6tables -t raw -A PREROUTING -m ipv6header --header ipv6-frag --soft -j CT --notrack


This is an example only which doesn't make much sense.







share|improve this answer














share|improve this answer



share|improve this answer








edited Apr 23 at 18:16

























answered Apr 22 at 20:05









A.BA.B

2,0042817




2,0042817












  • added that a packet, including fragments, can also be marked as notrack for further (non stateful) processing after the raw table.

    – A.B
    Apr 23 at 18:17


















  • added that a packet, including fragments, can also be marked as notrack for further (non stateful) processing after the raw table.

    – A.B
    Apr 23 at 18:17

















added that a packet, including fragments, can also be marked as notrack for further (non stateful) processing after the raw table.

– A.B
Apr 23 at 18:17






added that a packet, including fragments, can also be marked as notrack for further (non stateful) processing after the raw table.

– A.B
Apr 23 at 18:17


















draft saved

draft discarded
















































Thanks for contributing an answer to Server Fault!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f964072%2fhow-to-block-incoming-ipv6-fragments%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Club Baloncesto Breogán Índice Historia | Pavillón | Nome | O Breogán na cultura popular | Xogadores | Adestradores | Presidentes | Palmarés | Historial | Líderes | Notas | Véxase tamén | Menú de navegacióncbbreogan.galCadroGuía oficial da ACB 2009-10, páxina 201Guía oficial ACB 1992, páxina 183. Editorial DB.É de 6.500 espectadores sentados axeitándose á última normativa"Estudiantes Junior, entre as mellores canteiras"o orixinalHemeroteca El Mundo Deportivo, 16 setembro de 1970, páxina 12Historia do BreogánAlfredo Pérez, o último canoneiroHistoria C.B. BreogánHemeroteca de El Mundo DeportivoJimmy Wright, norteamericano do Breogán deixará Lugo por ameazas de morteResultados de Breogán en 1986-87Resultados de Breogán en 1990-91Ficha de Velimir Perasović en acb.comResultados de Breogán en 1994-95Breogán arrasa al Barça. "El Mundo Deportivo", 27 de setembro de 1999, páxina 58CB Breogán - FC BarcelonaA FEB invita a participar nunha nova Liga EuropeaCharlie Bell na prensa estatalMáximos anotadores 2005Tempada 2005-06 : Tódolos Xogadores da Xornada""Non quero pensar nunha man negra, mais pregúntome que está a pasar""o orixinalRaúl López, orgulloso dos xogadores, presume da boa saúde económica do BreogánJulio González confirma que cesa como presidente del BreogánHomenaxe a Lisardo GómezA tempada do rexurdimento celesteEntrevista a Lisardo GómezEl COB dinamita el Pazo para forzar el quinto (69-73)Cafés Candelas, patrocinador del CB Breogán"Suso Lázare, novo presidente do Breogán"o orixinalCafés Candelas Breogán firma el mayor triunfo de la historiaEl Breogán realizará 17 homenajes por su cincuenta aniversario"O Breogán honra ao seu fundador e primeiro presidente"o orixinalMiguel Giao recibiu a homenaxe do PazoHomenaxe aos primeiros gladiadores celestesO home que nos amosa como ver o Breo co corazónTita Franco será homenaxeada polos #50anosdeBreoJulio Vila recibirá unha homenaxe in memoriam polos #50anosdeBreo"O Breogán homenaxeará aos seus aboados máis veteráns"Pechada ovación a «Capi» Sanmartín e Ricardo «Corazón de González»Homenaxe por décadas de informaciónPaco García volve ao Pazo con motivo do 50 aniversario"Resultados y clasificaciones""O Cafés Candelas Breogán, campión da Copa Princesa""O Cafés Candelas Breogán, equipo ACB"C.B. Breogán"Proxecto social"o orixinal"Centros asociados"o orixinalFicha en imdb.comMario Camus trata la recuperación del amor en 'La vieja música', su última película"Páxina web oficial""Club Baloncesto Breogán""C. B. Breogán S.A.D."eehttp://www.fegaba.com

Vilaño, A Laracha Índice Patrimonio | Lugares e parroquias | Véxase tamén | Menú de navegación43°14′52″N 8°36′03″O / 43.24775, -8.60070

Cegueira Índice Epidemioloxía | Deficiencia visual | Tipos de cegueira | Principais causas de cegueira | Tratamento | Técnicas de adaptación e axudas | Vida dos cegos | Primeiros auxilios | Crenzas respecto das persoas cegas | Crenzas das persoas cegas | O neno deficiente visual | Aspectos psicolóxicos da cegueira | Notas | Véxase tamén | Menú de navegación54.054.154.436928256blindnessDicionario da Real Academia GalegaPortal das Palabras"International Standards: Visual Standards — Aspects and Ranges of Vision Loss with Emphasis on Population Surveys.""Visual impairment and blindness""Presentan un plan para previr a cegueira"o orixinalACCDV Associació Catalana de Cecs i Disminuïts Visuals - PMFTrachoma"Effect of gene therapy on visual function in Leber's congenital amaurosis"1844137110.1056/NEJMoa0802268Cans guía - os mellores amigos dos cegosArquivadoEscola de cans guía para cegos en Mortágua, PortugalArquivado"Tecnología para ciegos y deficientes visuales. Recopilación de recursos gratuitos en la Red""Colorino""‘COL.diesis’, escuchar los sonidos del color""COL.diesis: Transforming Colour into Melody and Implementing the Result in a Colour Sensor Device"o orixinal"Sistema de desarrollo de sinestesia color-sonido para invidentes utilizando un protocolo de audio""Enseñanza táctil - geometría y color. Juegos didácticos para niños ciegos y videntes""Sistema Constanz"L'ocupació laboral dels cecs a l'Estat espanyol està pràcticament equiparada a la de les persones amb visió, entrevista amb Pedro ZuritaONCE (Organización Nacional de Cegos de España)Prevención da cegueiraDescrición de deficiencias visuais (Disc@pnet)Braillín, un boneco atractivo para calquera neno, con ou sen discapacidade, que permite familiarizarse co sistema de escritura e lectura brailleAxudas Técnicas36838ID00897494007150-90057129528256DOID:1432HP:0000618D001766C10.597.751.941.162C97109C0155020