f-56: agent: MTU unique network.mtu_vm, underlay à 9000 contrôlé à la création, option DHCP 26 et host_mtu #56
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
parent
a729cf8891
commit
a94557d0ca
37 changed files with 518 additions and 24 deletions
|
|
@ -29,3 +29,7 @@ func newTestServerWith(t *testing.T, cfg *configuration.Config) (*Server, *badge
|
|||
d := dispatcher.New(q, db, cfg, logger)
|
||||
return New(d, db, logger, "127.0.0.1:0"), db
|
||||
}
|
||||
|
||||
func init() {
|
||||
dispatcher.LinkMTU = func(string) (int, error) { return 9000, nil }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ func (s Subnet) toConfig() (dhcpd.SubnetConfig, error) {
|
|||
return dhcpd.SubnetConfig{}, fmt.Errorf("invalid interface ip %q", s.InterfaceIP)
|
||||
}
|
||||
|
||||
c := dhcpd.SubnetConfig{Network: network, InterfaceIP: interfaceIP}
|
||||
c := dhcpd.SubnetConfig{Network: network, InterfaceIP: interfaceIP, MTU: s.MTU}
|
||||
|
||||
if s.VPCRoute != "" {
|
||||
if _, c.VPCRoute, err = net.ParseCIDR(s.VPCRoute); err != nil {
|
||||
|
|
@ -48,6 +48,7 @@ func subnetFromConfig(c dhcpd.SubnetConfig) Subnet {
|
|||
s := Subnet{
|
||||
Network: c.Network.String(),
|
||||
InterfaceIP: c.InterfaceIP.String(),
|
||||
MTU: c.MTU,
|
||||
}
|
||||
if c.VPCRoute != nil {
|
||||
s.VPCRoute = c.VPCRoute.String()
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ func CanonicalSubnet(s Subnet) (Subnet, error) {
|
|||
return Subnet{}, err
|
||||
}
|
||||
|
||||
out := Subnet{Network: network, InterfaceIP: interfaceIP}
|
||||
out := Subnet{Network: network, InterfaceIP: interfaceIP, MTU: s.MTU}
|
||||
|
||||
if s.VPCRoute != "" {
|
||||
if out.VPCRoute, err = canonicalCIDR(s.VPCRoute); err != nil {
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ type Subnet struct {
|
|||
InterfaceIP string `json:"interface_ip"`
|
||||
VPCRoute string `json:"vpc_route,omitempty"`
|
||||
DefaultGateway string `json:"default_gateway,omitempty"`
|
||||
MTU int `json:"mtu,omitempty"`
|
||||
}
|
||||
|
||||
type Host struct {
|
||||
|
|
@ -38,6 +39,7 @@ type Lease struct {
|
|||
Router string `json:"router,omitempty"`
|
||||
DNS []string `json:"dns"`
|
||||
Routes []string `json:"routes"`
|
||||
MTU uint16 `json:"mtu,omitempty"`
|
||||
LeaseSeconds uint32 `json:"lease_seconds"`
|
||||
}
|
||||
|
||||
|
|
|
|||
44
internal/api/dhcp/mtu_test.go
Normal file
44
internal/api/dhcp/mtu_test.go
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
package dhcpapi
|
||||
|
||||
import (
|
||||
"net"
|
||||
"testing"
|
||||
|
||||
"git.g3e.fr/syonad/two/internal/dhcpd"
|
||||
"github.com/insomniacslk/dhcp/dhcpv4"
|
||||
)
|
||||
|
||||
func TestSubnet_MTUSurvivesTheConversions(t *testing.T) {
|
||||
c, err := Subnet{Network: "10.0.5.0/24", InterfaceIP: "10.0.5.1", MTU: 1450}.toConfig()
|
||||
if err != nil {
|
||||
t.Fatalf("toConfig : %v", err)
|
||||
}
|
||||
if c.MTU != 1450 {
|
||||
t.Errorf("toConfig : mtu %d", c.MTU)
|
||||
}
|
||||
if got := subnetFromConfig(c).MTU; got != 1450 {
|
||||
t.Errorf("subnetFromConfig : mtu %d", got)
|
||||
}
|
||||
canonical, err := CanonicalSubnet(Subnet{Network: "10.0.5.0/24", InterfaceIP: "10.0.5.1", MTU: 1450})
|
||||
if err != nil || canonical.MTU != 1450 {
|
||||
t.Errorf("CanonicalSubnet : %+v, %v", canonical, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLeaseFromReply_ShowsTheMTU(t *testing.T) {
|
||||
_, network, _ := net.ParseCIDR("10.0.5.0/24")
|
||||
mac, _ := net.ParseMAC("00:22:33:00:00:0a")
|
||||
c := dhcpd.SubnetConfig{Network: network, InterfaceIP: net.ParseIP("10.0.5.1"), MTU: 1450}
|
||||
h := dhcpd.Host{MAC: mac, IP: net.ParseIP("10.0.5.10")}
|
||||
req, err := dhcpv4.New(dhcpv4.WithMessageType(dhcpv4.MessageTypeRequest), dhcpv4.WithHwAddr(mac))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
reply, err := dhcpd.BuildReply(c, h, req)
|
||||
if err != nil {
|
||||
t.Fatalf("BuildReply : %v", err)
|
||||
}
|
||||
if got := leaseFromReply(mac, reply).MTU; got != 1450 {
|
||||
t.Errorf("lease.MTU = %d, attendu 1450", got)
|
||||
}
|
||||
}
|
||||
|
|
@ -186,5 +186,8 @@ func leaseFromReply(mac net.HardwareAddr, reply *dhcpv4.DHCPv4) *Lease {
|
|||
for _, route := range reply.ClasslessStaticRoute() {
|
||||
lease.Routes = append(lease.Routes, route.Dest.String()+" via "+route.Router.String())
|
||||
}
|
||||
if mtu, err := dhcpv4.GetUint16(dhcpv4.OptionInterfaceMTU, reply.Options); err == nil {
|
||||
lease.MTU = mtu
|
||||
}
|
||||
return lease
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue