Skip to content

Commit

Permalink
add ipv6 support
Browse files Browse the repository at this point in the history
  • Loading branch information
Magnus Kaiser committed Sep 10, 2024
1 parent e78fe64 commit 441f45d
Show file tree
Hide file tree
Showing 8 changed files with 196 additions and 500 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
[![Go Doc](https://godoc.org/github.com/exaring/pmtud?status.svg)](https://godoc.org/github.com/exaring/pmtud)

In ECMP or L4 load balanced environments ICMP messages are mostly routed to the wrong servers.
Path MTU Discovery Daemon solves this problem by "broadcasting" received ICMP packet too big messages to all backend instances of an L3/L4 load balanced service using IPIP encapsulation.
Path MTU Discovery Daemon solves this problem by "broadcasting" received ICMP packet too big messages to all backend
instances of an L3/L4 load balanced service using IPIP ([RFC2003](https://datatracker.ietf.org/doc/html/rfc2003))
(legacy IP) and IPv6 Encapsulation ([RFC2473](https://datatracker.ietf.org/doc/html/rfc2473#section-3) (IPv6).

Some Details:

* https://tools.ietf.org/html/draft-jaeggli-v6ops-pmtud-ecmp-problem-00
Expand All @@ -31,4 +34,6 @@ interfaces: ["enp4s0"]
backends:
- 10.0.0.0
- 10.0.0.1
- 2001:db8::1
- 2001:db8::2
```
2 changes: 2 additions & 0 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ interfaces: ["enp4s0"]
backends:
- 192.0.2.0
- 192.0.2.1
- 2001:db8::1
- 2001:db8::2
24 changes: 17 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
module github.com/exaring/pmtud

go 1.15
go 1.23

require (
github.com/google/gopacket v1.1.19
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.9.0
github.com/q3k/goveralls v0.1.0
github.com/sirupsen/logrus v1.8.1
go.uber.org/zap v1.16.0
golang.org/x/net v0.0.0-20210316092652-d523dce5a7f4
github.com/prometheus/client_golang v1.20.3
go.uber.org/zap v1.27.0
golang.org/x/net v0.29.0
gopkg.in/yaml.v2 v2.4.0
)

require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/klauspost/compress v1.17.9 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.59.1 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/sys v0.25.0 // indirect
google.golang.org/protobuf v1.34.2 // indirect
)
452 changes: 50 additions & 402 deletions go.sum

Large diffs are not rendered by default.

13 changes: 8 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"flag"
"log"
"net/http"

"github.com/exaring/pmtud/pkg/config"
Expand All @@ -10,8 +11,6 @@ import (

"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"

log "github.com/sirupsen/logrus"
)

var (
Expand All @@ -23,24 +22,28 @@ func main() {

cfg, err := config.GetConfig(*cfgFilePath)
if err != nil {
log.WithError(err).Fatal("Unable to get config")
log.Fatalf("unable to get config: %s", err)
}

relays := make([]*icmp34relay.Relay, 0)
for _, ifa := range cfg.Interfaces {
relay, err := icmp34relay.New(ifa, cfg.GetBackends())
if err != nil {
log.WithError(err).Fatal("Unable to get ICMP34 relay")
log.Fatalf("unable to get ICMP34 relay: %s", err)
}

err = relay.Start()
if err != nil {
log.WithError(err).Fatal("Unable to start relay")
log.Fatalf("unable to start relay: %s", err)
}

relays = append(relays, relay)
}

if len(relays) == 0 {
log.Fatal("no matching interface found")
}

m := metrics.New(relays)
prometheus.Register(m)

Expand Down
24 changes: 12 additions & 12 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
package config

import (
"io/ioutil"
"net"
"fmt"
"net/netip"
"os"

"github.com/pkg/errors"
"gopkg.in/yaml.v2"
)

// Config represents a config file
type Config struct {
Interfaces []string `yaml:"interfaces"`
Backends []string `yaml:"backends"`
backends []net.IP
backends []netip.Addr
}

// GetConfig gets the config
func GetConfig(fp string) (*Config, error) {
fc, err := ioutil.ReadFile(fp)
fc, err := os.ReadFile(fp)
if err != nil {
return nil, errors.Wrap(err, "Unable to read file")
return nil, fmt.Errorf("Unable to read file: %w", err)
}

cfg := &Config{
Interfaces: make([]string, 0),
Backends: make([]string, 0),
backends: make([]net.IP, 0),
backends: make([]netip.Addr, 0),
}

err = yaml.Unmarshal(fc, cfg)
if err != nil {
return nil, errors.Wrap(err, "Unable to unmarshal YAML file")
return nil, fmt.Errorf("Unable to unmarshal YAML file: %w", err)
}

for _, b := range cfg.Backends {
a := net.ParseIP(b)
if a == nil {
return nil, errors.Wrapf(err, "Unable to parse IP: %s", b)
a, err := netip.ParseAddr(b)
if err != nil {
return nil, fmt.Errorf("Unable to parse IP '%s': %w", b, err)
}

cfg.backends = append(cfg.backends, a)
Expand All @@ -46,6 +46,6 @@ func GetConfig(fp string) (*Config, error) {
}

// GetBackends gets the backends
func (c *Config) GetBackends() []net.IP {
func (c *Config) GetBackends() []netip.Addr {
return c.backends
}
Loading

0 comments on commit 441f45d

Please sign in to comment.