Page MenuHomeFreeBSD

gre(4): Add full support for gre key
Needs ReviewPublic

Authored by pouria on Sat, Sep 19, 8:06 PM.

Details

Reviewers
adrian
glebius
markj
Group Reviewers
network
Summary

Allow multiple gre tunnels with same source and destination
tunnel with different gre keys.
Add a net.link.gre.key_fallback for backward compatibility
and set it to true by default.
Also write multikey tests for both IPv4 and IPv6 families.

Relnotes: yes

Test Plan

Create two tunnel with the same source and destination but with different gre key:

# ifconfig gre0 create inet tunnel 172.23.1.123 172.23.1.1 grekey 1
# ifconfig gre1 create inet tunnel 172.23.1.123 172.23.1.1 grekey 2
# ifconfig -a -g gre
gre0: flags=8050<POINTOPOINT,RUNNING,MULTICAST> metric 0 mtu 1476
        options=80000<LINKSTATE>
        tunnel inet 172.23.1.123 --> 172.23.1.1
        groups: gre
        grekey: 0x1 (1)
        nd6 options=829<PERFORMNUD,IFDISABLED,AUTO_LINKLOCAL,STABLEADDR>
gre1: flags=8050<POINTOPOINT,RUNNING,MULTICAST> metric 0 mtu 1476
        options=80000<LINKSTATE>
        tunnel inet 172.23.1.123 --> 172.23.1.1
        groups: gre
        grekey: 0x2 (2)
        nd6 options=829<PERFORMNUD,IFDISABLED,AUTO_LINKLOCAL,STABLEADDR>
# kyua test -k /usr/tests/Kyuafile sys/net/if_gre
sys/net/if_gre:gre6_basic  ->  passed  [1.330s]
sys/net/if_gre:gre6_csum  ->  passed  [1.490s]
sys/net/if_gre:gre4_key_fallback  ->  passed  [2.811s]
sys/net/if_gre:gre4_basic  ->  passed  [2.951s]
sys/net/if_gre:gre4_multikey  ->  passed  [2.836s]
sys/net/if_gre:gre4_key_mismatch_udpencap  ->  passed  [4.616s]
sys/net/if_gre:gre4_multikey_udpencap  ->  passed  [5.907s]
sys/net/if_gre:gre6_key  ->  passed  [3.830s]
sys/net/if_gre:gre4_key_mismatch  ->  passed  [7.565s]
sys/net/if_gre:gre_blind_options  ->  passed  [1.875s]
sys/net/if_gre:gre6_seq  ->  passed  [4.764s]
sys/net/if_gre:gre6_udpencap  ->  passed  [4.274s]
sys/net/if_gre:gre6_multikey  ->  passed  [8.662s]
sys/net/if_gre:gre6_multikey_udpencap  ->  passed  [6.621s]

Results file id is usr_tests.20260919-200756-603017
Results saved to /root/.kyua/store/results.usr_tests.20260919-200756-603017.db

14/14 passed (0 broken, 0 failed, 0 skipped)

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 77099
Build 73982: arc lint + arc unit

Event Timeline

pouria held this revision as a draft.
pouria published this revision for review.Sat, Sep 19, 8:29 PM

I really want to keep gre simple and use my own geneve driver. but censorship in my country is not geneve friendly...
Tests are similar to each other, but they're important because we separate ipv4 and ipv6 logic.

Since I didn't touch the hash table logic. the proposed change is quite simple.
most of the logic is around net.link.gre.key_fallback for backward compatibility.
I'd be glad to remove the fallback logic, but beside our own compatibility break, Linux can be configured with separate inbound/outbound key.
So I decided to keep the fallback for now.

sys/net/if_gre.c
772

gre checksum is optinal and if set, it consume 16 bit for checksum and other 16 bit reserved. We need to skip those fields in order to access gre key.
I didn't want to add another comment here. it makes it ugly or I should use extra {} for my if condition to make it pretty again, which is unnecessary :)