Skip to content

Commit 7913d8d

Browse files
authored
Refactor (#11)
1 parent 216e6b1 commit 7913d8d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+3345
-1039
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
nextmn-srv6
2+
srv6
23
!bash-completion/completions/nextmn-srv6

Makefile

+11-5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ prefix = /usr/local
22
exec_prefix = $(prefix)
33
bindir = $(exec_prefix)/bin
44
BASHCOMPLETIONSDIR = $(exec_prefix)/share/bash-completion/completions
5+
IPROUTE2_RTPROTOS_D = /etc/iproute2/rt_protos.d
6+
IPROUTE2_RTTABLES_D = /etc/iproute2/rt_tables.d
57

68

79
RM = rm -f
@@ -17,12 +19,16 @@ reinstall: uninstall install
1719
update:
1820
go mod tidy
1921
install:
20-
$(INSTALL) nextmn-srv6 $(DESTDIR)$(bindir)/nextmn-srv6
21-
$(INSTALL) bash-completion/completions/nextmn-srv6 $(DESTDIR)$(BASHCOMPLETIONSDIR)/nextmn-srv6
22+
$(INSTALL) srv6 $(DESTDIR)$(bindir)/srv6
23+
$(INSTALL) etc/iproute2/rt_protos.d/nextmn.conf $(DESTDIR)$(IPROUTE2_RTPROTOS_D)/nextmn.conf
24+
$(INSTALL) etc/iproute2/rt_tables.d/nextmn.conf $(DESTDIR)$(IPROUTE2_RTTABLES_D)/nextmn.conf
25+
$(INSTALL) bash-completion/completions/srv6 $(DESTDIR)$(BASHCOMPLETIONSDIR)/srv6
2226
@echo "================================="
2327
@echo ">> Now run the following command:"
24-
@echo "\tsource $(DESTDIR)$(BASHCOMPLETIONSDIR)/nextmn-srv6"
28+
@echo "\tsource $(DESTDIR)$(BASHCOMPLETIONSDIR)/srv6"
2529
@echo "================================="
2630
uninstall:
27-
$(RM) $(DESTDIR)$(bindir)/nextmn-srv6
28-
$(RM) $(DESTDIR)$(BASHCOMPLETIONSDIR)/nextmn-srv6
31+
$(RM) $(DESTDIR)$(bindir)/srv6
32+
$(RM) $(DESTDIR)$(BASHCOMPLETIONSDIR)/srv6
33+
$(RM) $(DESTDIR)$(IPROUTE2_RTPROTOS_D)/nextmn.conf
34+
$(RM) $(DESTDIR)$(IPROUTE2_RTTABLES_D)/nextmn.conf

README.md

+18-10
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,34 @@ This project is still at the early stages of development and contains bugs and w
44
Please do not use it for anything other than experimentation. Expect breaking changes until v1.0.0
55

66
## Roadmap
7-
Behavior | Implemented? | Todo
8-
---|---|---
9-
End.MAP | no | -
10-
End.M.GTP6.D | no | -
11-
End.M.GTP6.D.Di | partial | handle GTP6 packets using go-packet instead of go-gtp, respect S04, send ICMP when errors, optional: respond to GTP Echo Req
12-
End.M.GTP6.E | partial | create GTP6 packets using go-packet instead of go-gtp, send ICMP when errors
13-
End.M.GTP4.E | partial | create GTP4 packets using go-packet instead of go-gtp, send ICMP when errors, IPv4 SA from SRv6 DA
14-
H.M.GTP4.D | partial | handle GTP4 packets using go-packets instead of go-gtp, send ArgsMobSession and IPv4 DA, send ICMP when errors, optional: respond to GTP Echo Req
15-
End.Limit | no | -
7+
Provider | Behavior | Implemented? | Todo
8+
---|---|---|---
9+
NextMN | End.MAP | no | -
10+
NextMN | End.M.GTP6.D | no | -
11+
NextMN | End.M.GTP6.D.Di | no | -
12+
NextMN | End.M.GTP6.E | yes | send ICMP when errors
13+
NextMN | End.M.GTP4.E | yes | send ICMP when errors
14+
NextMN | H.M.GTP4.D | yes | send ICMP when errors, optional: respond to GTP Echo Req
15+
NextMN | End.Limit | no | -
16+
Linux | End | yes | -
17+
Linux | End.DX4 | yes | -
18+
Linux | H.Encaps | yes | -
19+
Linux | H.Inline | untested | -
1620

1721
PDU Session Type | Supported?
1822
---|---
1923
IPv4 | partial
20-
IPv6 | partial
24+
IPv6 | no
2125
IPv4v6 | yes
2226
Ethernet | no
2327
Unstructured | no
2428

2529
TODO: SR Policy set by [nextmn-srv6-ctrl](https://github.com/louisroyer/nextmn-srv6-ctrl).
2630

31+
32+
## Testbed
33+
- [louisroyer/test-srv6-stateless](https://github.com/louisroyer/test-srv6-stateless)
34+
2735
## Getting started
2836
### Build dependencies
2937
- golang

bash-completion/completions/nextmn-srv6

-21
This file was deleted.

config/config.yaml

+36-10
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,40 @@
1-
iproute2:
2-
rttable-number: 100
3-
rtproto-number: 100
1+
#hooks:
2+
# pre-init-hook:
3+
# post-init-hook:
4+
# pre-exit-hook:
5+
# post-exit-hook:
6+
7+
linux-headend-set-source-address: "fd00:51D5:0000::"
8+
ipv4-headend-prefix: "10.0.200.3/32"
9+
headends:
10+
- name: "gtp4 to sr"
11+
to: "10.0.200.3/32"
12+
provider: "NextMN"
13+
behavior: "H.M.GTP4.D"
14+
policy:
15+
- match:
16+
teid: 0x0001
17+
bsid:
18+
bsid-prefix: "fd00:51D5:000:2::/80"
19+
segments-list:
20+
- "fd00:51D5:0000:3::"
21+
- "fd00:51D5:0000:4::"
22+
source-address-prefix: "fd00:51D5:000:1:9999::/80"
23+
- name: "linux test"
24+
to: "10.0.300.0/24"
25+
provider: "Linux"
26+
behavior: "H.Encaps"
27+
policy:
28+
- bsid:
29+
segments-list:
30+
- "fd00:51D5:0000:2::"
31+
- "fd00:51D5:0000:3::"
32+
433
locator: "fd00:51D5:0000:1::/64"
534
endpoints:
6-
- sid: "fd00:51D5:0000:1:11::/80"
35+
- prefix: "fd00:51D5:0000:1:11::/80"
736
behavior: "End.DX4"
8-
- sid: "fd00:51D5:0000:1:1::/80"
37+
provider: "Linux"
38+
- prefix: "fd00:51D5:0000:1:1::/80"
939
behavior: "End"
10-
11-
policy:
12-
segments-list:
13-
- "fd00:51D5:0000:2::"
14-
- "fd00:51D5:0000:3::"
40+
provider: "Linux"

etc/iproute2/rt_protos.d/nextmn.conf

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Additional protocol strings defined by nextmn
2+
# If you are a package maintainer and
3+
# the following proto numbers are conflicting with
4+
# other packages, feel free to replace them.
5+
6+
88 nextmn

etc/iproute2/rt_tables.d/nextmn.conf

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Additional tables managed by nextmn
2+
# If you are a package maintainer and
3+
# the following table numbers are conflicting with
4+
# other packages, feel free to replace them.
5+
6+
# Attribution method:
7+
# 1. The number for the first table has been generated by random.
8+
# 2. For each other line, number previous line's one incremented by one.
9+
10+
41407 nextmn/ipv6
11+
41408 nextmn/ipv4

go.mod

+7-9
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
1-
module github.com/louisroyer/nextmn-srv6
1+
module github.com/nextmn/srv6
22

33
go 1.19
44

55
require (
6+
github.com/google/go-cmp v0.6.0
67
github.com/google/gopacket v1.1.19
7-
github.com/louisroyer/gopacket-srv6 v0.0.5
8+
github.com/louisroyer/gopacket-gtp v0.0.5
9+
github.com/louisroyer/gopacket-srv6 v0.0.6
810
github.com/songgao/water v0.0.0-20200317203138-2b4b6d7c09d8
9-
github.com/urfave/cli/v2 v2.25.1
10-
github.com/wmnsk/go-gtp v0.8.6
11+
github.com/urfave/cli/v2 v2.25.7
1112
gopkg.in/yaml.v3 v3.0.1
1213
)
1314

1415
require (
15-
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
16+
github.com/cpuguy83/go-md2man/v2 v2.0.3 // indirect
1617
github.com/russross/blackfriday/v2 v2.1.0 // indirect
17-
github.com/vishvananda/netlink v1.1.0 // indirect
18-
github.com/vishvananda/netns v0.0.0-20211101163701-50045581ed74 // indirect
1918
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
20-
golang.org/x/net v0.0.0-20220407224826-aac1ed45d8e3 // indirect
21-
golang.org/x/sys v0.8.0 // indirect
19+
golang.org/x/sys v0.13.0 // indirect
2220
)

go.sum

+12-21
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,21 @@
1-
github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w=
2-
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
3-
github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=
1+
github.com/cpuguy83/go-md2man/v2 v2.0.3 h1:qMCsGGgs+MAzDFyp9LpAe1Lqy/fY/qCovCm0qnXZOBM=
2+
github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
3+
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
4+
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
45
github.com/google/gopacket v1.1.19 h1:ves8RnFZPGiFnTS0uPQStjwru6uO6h+nlr9j6fL7kF8=
56
github.com/google/gopacket v1.1.19/go.mod h1:iJ8V8n6KS+z2U1A8pUwu8bW5SyEMkXJB8Yo/Vo+TKTo=
6-
github.com/louisroyer/gopacket-srv6 v0.0.4 h1:ICfvXcUYdh6McY59zn2kwN9lpMWUQrV3kd+iPhWjLNg=
7-
github.com/louisroyer/gopacket-srv6 v0.0.4/go.mod h1:AifV+WVuFi3c9fOohh2EgERRJJY2BO1AVPf0GRdrNzo=
7+
github.com/louisroyer/gopacket-gtp v0.0.5 h1:3k67pLeHJPeIVt4zUxOpL0weVP0ANimHWK0Sdq7MILA=
8+
github.com/louisroyer/gopacket-gtp v0.0.5/go.mod h1:/gtAnzNjcQlADZgX46340wS8eNtuk4CKELYmLQbynGU=
89
github.com/louisroyer/gopacket-srv6 v0.0.5 h1:DyyL9u6XwTeULsPKq5zs+MYyo0oZjN5Kas1N1SCXmzE=
910
github.com/louisroyer/gopacket-srv6 v0.0.5/go.mod h1:AifV+WVuFi3c9fOohh2EgERRJJY2BO1AVPf0GRdrNzo=
10-
github.com/pascaldekloe/goe v0.1.0 h1:cBOtyMzM9HTpWjXfbbunk26uA6nG3a8n06Wieeh0MwY=
11+
github.com/louisroyer/gopacket-srv6 v0.0.6 h1:/ElsYLQmhXvirf5zWke6nCgaGq+Az4rUd0FzlhS2fNw=
12+
github.com/louisroyer/gopacket-srv6 v0.0.6/go.mod h1:AifV+WVuFi3c9fOohh2EgERRJJY2BO1AVPf0GRdrNzo=
1113
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
1214
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
1315
github.com/songgao/water v0.0.0-20200317203138-2b4b6d7c09d8 h1:TG/diQgUe0pntT/2D9tmUCz4VNwm9MfrtPr0SU2qSX8=
1416
github.com/songgao/water v0.0.0-20200317203138-2b4b6d7c09d8/go.mod h1:P5HUIBuIWKbyjl083/loAegFkfbFNx5i2qEP4CNbm7E=
15-
github.com/urfave/cli/v2 v2.25.1 h1:zw8dSP7ghX0Gmm8vugrs6q9Ku0wzweqPyshy+syu9Gw=
16-
github.com/urfave/cli/v2 v2.25.1/go.mod h1:GHupkWPMM0M/sj1a2b4wUrWBPzazNrIjouW6fmdJLxc=
17-
github.com/vishvananda/netlink v1.1.0 h1:1iyaYNBLmP6L0220aDnYQpo1QEV4t4hJ+xEEhhJH8j0=
18-
github.com/vishvananda/netlink v1.1.0/go.mod h1:cTgwzPIzzgDAYoQrMm0EdrjRUBkTqKYppBueQtXaqoE=
19-
github.com/vishvananda/netns v0.0.0-20191106174202-0a2b9b5464df/go.mod h1:JP3t17pCcGlemwknint6hfoeCVQrEMVwxRLRjXpq+BU=
20-
github.com/vishvananda/netns v0.0.0-20211101163701-50045581ed74 h1:gga7acRE695APm9hlsSMoOoE65U4/TcqNj90mc69Rlg=
21-
github.com/vishvananda/netns v0.0.0-20211101163701-50045581ed74/go.mod h1:DD4vA1DwXk04H54A1oHXtwZmA0grkVMdPxx/VGLCah0=
22-
github.com/wmnsk/go-gtp v0.8.6 h1:Z2lHnNlQ49jdySoWpcZPOsGPFjDb+5BQm9rO9Nn47E0=
23-
github.com/wmnsk/go-gtp v0.8.6/go.mod h1:7Ja5ik6qMx451Oa4LXdXYl53277fL/X7Ob8nCb5T6TY=
17+
github.com/urfave/cli/v2 v2.25.7 h1:VAzn5oq403l5pHjc4OhD54+XGO9cdKVL/7lDjF+iKUs=
18+
github.com/urfave/cli/v2 v2.25.7/go.mod h1:8qnjx1vcq5s2/wpsqoZFndg2CE5tNFyrTvS6SinrnYQ=
2419
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU=
2520
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8=
2621
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
@@ -29,15 +24,11 @@ golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPI
2924
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
3025
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
3126
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
32-
golang.org/x/net v0.0.0-20220407224826-aac1ed45d8e3 h1:EN5+DfgmRMvRUrMGERW2gQl3Vc+Z7ZMnI/xdEpPSf0c=
33-
golang.org/x/net v0.0.0-20220407224826-aac1ed45d8e3/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
3427
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
3528
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
3629
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
37-
golang.org/x/sys v0.0.0-20190606203320-7fc4e5ec1444/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
38-
golang.org/x/sys v0.0.0-20200217220822-9197077df867/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
39-
golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU=
40-
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
30+
golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=
31+
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
4132
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
4233
golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
4334
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=

internal/app/api/registry.go

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright 2023 Louis Royer and the NextMN-SRv6 contributors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style license that can be
3+
// found in the LICENSE file.
4+
// SPDX-License-Identifier: MIT
5+
package app_api
6+
7+
import "github.com/nextmn/srv6/internal/iproute2"
8+
9+
type Registry interface {
10+
// ifaces
11+
TunIface(name string) (*iproute2.TunIface, bool)
12+
RegisterTunIface(iface *iproute2.TunIface) error
13+
DeleteTunIface(name string)
14+
}

internal/app/registry.go

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright 2023 Louis Royer and the NextMN-SRv6 contributors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style license that can be
3+
// found in the LICENSE file.
4+
// SPDX-License-Identifier: MIT
5+
package app
6+
7+
import (
8+
"fmt"
9+
10+
"github.com/nextmn/srv6/internal/iproute2"
11+
)
12+
13+
type Registry struct {
14+
ifaces map[string]*iproute2.TunIface
15+
}
16+
17+
func NewRegistry() *Registry {
18+
return &Registry{
19+
ifaces: make(map[string]*iproute2.TunIface),
20+
}
21+
}
22+
23+
func (r *Registry) TunIface(name string) (*iproute2.TunIface, bool) {
24+
iface, exists := r.ifaces[name]
25+
return iface, exists
26+
}
27+
28+
func (r *Registry) RegisterTunIface(iface *iproute2.TunIface) error {
29+
if _, exists := r.ifaces[iface.Name()]; exists {
30+
return fmt.Errorf("Iface %s is already registered.", iface.Name())
31+
}
32+
r.ifaces[iface.Name()] = iface
33+
return nil
34+
}
35+
36+
func (r *Registry) DeleteTunIface(name string) {
37+
delete(r.ifaces, name)
38+
}

0 commit comments

Comments
 (0)