Skip to content

Commit

Permalink
wireguard: use allowed_ips only for nodes
Browse files Browse the repository at this point in the history
Signed-off-by: Nathan Skrzypczak <[email protected]>
  • Loading branch information
sknat committed Nov 2, 2023
1 parent af1ec91 commit 65effe7
Show file tree
Hide file tree
Showing 5 changed files with 210 additions and 221 deletions.
9 changes: 5 additions & 4 deletions calico-vpp-agent/connectivity/ipip.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,14 @@ func (p *IpipProvider) AddConnectivity(cn *common.NodeConnectivity) error {
p.errorCleanup(tunnel)
return errors.Wrapf(err, "Error setting ipip interface up")
}
p.log.Infof("connectivity(add) before route IPIP tunnel=%s", tunnel.String())

p.log.Debugf("Routing pod->node %s traffic into tunnel (swIfIndex %d)", cn.NextHop.String(), swIfIndex)
err = p.vpp.RouteAdd(&types.Route{
Dst: common.ToMaxLenCIDR(cn.NextHop),
Paths: []types.RoutePath{{
SwIfIndex: swIfIndex,
Gw: nil,
Gw: cn.NextHop,
}},
Table: common.PodVRFIndex,
})
Expand All @@ -166,7 +167,7 @@ func (p *IpipProvider) AddConnectivity(cn *common.NodeConnectivity) error {
Dst: &cn.Dst,
Paths: []types.RoutePath{{
SwIfIndex: tunnel.SwIfIndex,
Gw: nil,
Gw: cn.NextHop,
}},
}
err := p.vpp.RouteAdd(route)
Expand All @@ -191,7 +192,7 @@ func (p *IpipProvider) DelConnectivity(cn *common.NodeConnectivity) error {
Dst: &cn.Dst,
Paths: []types.RoutePath{{
SwIfIndex: tunnel.SwIfIndex,
Gw: nil,
Gw: cn.NextHop,
}},
}
err := p.vpp.RouteDel(routeToDelete)
Expand All @@ -208,7 +209,7 @@ func (p *IpipProvider) DelConnectivity(cn *common.NodeConnectivity) error {
Dst: common.ToMaxLenCIDR(cn.NextHop),
Paths: []types.RoutePath{{
SwIfIndex: tunnel.SwIfIndex,
Gw: nil,
Gw: cn.NextHop,
}},
Table: common.PodVRFIndex,
})
Expand Down
14 changes: 5 additions & 9 deletions calico-vpp-agent/connectivity/vxlan.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ func (p *VXLanProvider) AddConnectivity(cn *common.NodeConnectivity) error {
Dst: common.ToMaxLenCIDR(cn.NextHop),
Paths: []types.RoutePath{{
SwIfIndex: swIfIndex,
Gw: nil,
Gw: cn.NextHop,
}},
Table: common.PodVRFIndex,
})
Expand Down Expand Up @@ -251,7 +251,7 @@ func (p *VXLanProvider) AddConnectivity(cn *common.NodeConnectivity) error {
Dst: &cn.Dst,
Paths: []types.RoutePath{{
SwIfIndex: tunnel.SwIfIndex,
Gw: nodeIP, // FIXME this is probably wrong. The gateway of route going out to another node should not point to THIS node.
Gw: cn.NextHop,
}},
Table: table,
}
Expand All @@ -263,15 +263,11 @@ func (p *VXLanProvider) AddConnectivity(cn *common.NodeConnectivity) error {
return p.vpp.RouteAdd(route)
}

func (p *VXLanProvider) DelConnectivity(cn *common.NodeConnectivity) error {
func (p *VXLanProvider) DelConnectivity(cn *common.NodeConnectivity) (err error) {
tunnel, found := p.vxlanIfs[cn.NextHop.String()+"-"+fmt.Sprint(cn.Vni)]
if !found {
return errors.Errorf("Deleting unknown vxlan tunnel cn=%s", cn.String())
}
nodeIP, err := p.getNodeIpForConnectivity(cn)
if err != nil {
return err
}

var routeToDelete *types.Route
if cn.Vni == 0 {
Expand All @@ -280,7 +276,7 @@ func (p *VXLanProvider) DelConnectivity(cn *common.NodeConnectivity) error {
Dst: &cn.Dst,
Paths: []types.RoutePath{{
SwIfIndex: tunnel.SwIfIndex,
Gw: nodeIP,
Gw: cn.NextHop,
}},
}
} else {
Expand All @@ -290,7 +286,7 @@ func (p *VXLanProvider) DelConnectivity(cn *common.NodeConnectivity) error {
Dst: &cn.Dst,
Paths: []types.RoutePath{{
SwIfIndex: tunnel.SwIfIndex,
Gw: nodeIP,
Gw: cn.NextHop,
}},
Table: vrfIndex,
}
Expand Down
Loading

0 comments on commit 65effe7

Please sign in to comment.