Skip to content

Commit b148789

Browse files
committed
Add TranslateUplinkAddrMaskTo64 option only for non LL /128
This patch transforms the UplinkSubnetMask option to TranslateUplinkAddrMaskTo64 and restricts it to only apply to non linklocal v6 addresses read on the uplink interface, and that have a /128 prefix With the previous implementation we were trying to program VPP with LL /64 addresses which was returning errors. Also this patch makes it so that vpp-manager will error out if it fails programming VPP with an address so that we notice such errors Signed-off-by: Nathan Skrzypczak <nathan.skrzypczak@gmail.com>
1 parent 149f253 commit b148789

File tree

2 files changed

+24
-18
lines changed

2 files changed

+24
-18
lines changed

config/config.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -318,9 +318,12 @@ type CalicoVppDebugConfigType struct {
318318
// get the v6 link local address from the tap created in linux
319319
// to replace the uplink before giving up.
320320
FetchV6LLntries *uint32 `json:"fetchV6LLntries,omitempty"`
321-
// UplinkSubnetMask is the subnet mask we configure on the uplink
322-
// regardless of the source netmask from Linux interface.
323-
UplinkSubnetMask *uint16 `json:"uplinkSubnetMask,omitempty"`
321+
// TranslateUplinkAddrMaskTo64 if set will convert all the non link local
322+
// addresses read on the uplink interface that are [::ipv6]/128 to be [::ipv6]/64
323+
// this is enabled by default as VPP currently lacks the implementation of
324+
// getting the prefix over router advertisements with option L and !A
325+
// proper implementation will come in a later VPP patch.
326+
TranslateUplinkAddrMaskTo64 *bool `json:"translateUplinkAddrMaskTo64,omitempty"`
324327
}
325328

326329
func (cfg *CalicoVppDebugConfigType) String() string {
@@ -341,11 +344,8 @@ func (cfg *CalicoVppDebugConfigType) Validate() (err error) {
341344
if cfg.EnableUdevNetNameRules == nil {
342345
cfg.EnableUdevNetNameRules = &True
343346
}
344-
var uplinkSubnetMask uint16 = 64
345-
if cfg.UplinkSubnetMask == nil {
346-
cfg.UplinkSubnetMask = &uplinkSubnetMask
347-
} else if *cfg.UplinkSubnetMask == 0 || *cfg.UplinkSubnetMask > 128 {
348-
return errors.Errorf("uplinkSubnetMask must be in [1,128]")
347+
if cfg.TranslateUplinkAddrMaskTo64 == nil {
348+
cfg.TranslateUplinkAddrMaskTo64 = &True
349349
}
350350
var v uint32 = 5
351351
if cfg.FetchV6LLntries == nil {

vpp-manager/vpp_runner.go

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,23 @@ type VppRunner struct {
5050
uplinkDriver []uplink.UplinkDriver
5151
}
5252

53+
// getUplinkAddressWithMask will update the mask of an ipv6 address
54+
// and set it from /128 to /64 if the option 'TranslateUplinkAddrMaskTo64' is set
55+
// this will not update Link-local addresses
5356
func getUplinkAddressWithMask(addr *net.IPNet) *net.IPNet {
54-
if addr == nil || addr.IP == nil || addr.IP.To4() != nil {
57+
if addr == nil || addr.IP == nil || addr.IP.To4() != nil || addr.IP.IsLinkLocalUnicast() {
5558
return addr
5659
}
57-
subnetMask := uint16(64)
58-
if config.GetCalicoVppDebug().UplinkSubnetMask != nil {
59-
subnetMask = *config.GetCalicoVppDebug().UplinkSubnetMask
60+
if !*config.GetCalicoVppDebug().TranslateUplinkAddrMaskTo64 {
61+
return addr
62+
}
63+
ones, _ := addr.Mask.Size()
64+
if ones != 128 {
65+
return addr
6066
}
6167
return &net.IPNet{
6268
IP: addr.IP,
63-
Mask: net.CIDRMask(int(subnetMask), 128),
69+
Mask: net.CIDRMask(64, 128),
6470
}
6571
}
6672

@@ -521,10 +527,10 @@ func (v *VppRunner) configureVppUplinkInterface(
521527
}
522528

523529
for _, addr := range ifState.GetAddresses() {
524-
log.Infof("Adding address %s to uplink interface", addr.String())
530+
log.Infof("Adding address %s to uplink interface", getUplinkAddressWithMask(addr.IPNet).String())
525531
err = v.vpp.AddInterfaceAddress(ifSpec.SwIfIndex, getUplinkAddressWithMask(addr.IPNet))
526532
if err != nil {
527-
log.Errorf("Error adding address to uplink interface: %v", err)
533+
return errors.Wrapf(err, "Error adding address %s to uplink interface", getUplinkAddressWithMask(addr.IPNet))
528534
}
529535
}
530536
for _, route := range ifState.GetRoutes() {
@@ -657,13 +663,13 @@ func (v *VppRunner) configureVppUplinkInterface(
657663
}
658664

659665
if ifState.IPv6LinkLocal.IPNet != nil {
660-
err = v.vpp.AddInterfaceAddress(ifSpec.SwIfIndex, getUplinkAddressWithMask(common.FullyQualified(ifState.IPv6LinkLocal.IP)))
666+
err = v.vpp.AddInterfaceAddress(ifSpec.SwIfIndex, common.FullyQualified(ifState.IPv6LinkLocal.IP))
661667
if err != nil {
662-
log.Errorf("Error adding address to uplink interface: %v", err)
668+
return errors.Wrapf(err, "Error adding address %s to uplink interface: %d", common.FullyQualified(ifState.IPv6LinkLocal.IP), ifSpec.SwIfIndex)
663669
}
664670
err = v.vpp.EnableIP6NdProxy(tapSwIfIndex, ifState.IPv6LinkLocal.IP)
665671
if err != nil {
666-
log.Errorf("Error configuring nd proxy for address %s: %v", ifState.IPv6LinkLocal.IP.String(), err)
672+
return errors.Wrapf(err, "Error configuring nd proxy for address %s", ifState.IPv6LinkLocal.IP.String())
667673
}
668674
}
669675

0 commit comments

Comments
 (0)