Skip to content

Commit

Permalink
Vl3 next-hop fix (#1309)
Browse files Browse the repository at this point in the history
Signed-off-by: Artem Glazychev <artem.glazychev@xored.com>
  • Loading branch information
glazychev-art authored Jun 3, 2022
1 parent 74b8b0f commit 6abdf1e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
6 changes: 4 additions & 2 deletions pkg/networkservice/connectioncontext/ipcontext/vl3/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,12 @@ func (n *vl3Client) Request(ctx context.Context, request *networkservice.Network
conn.GetContext().GetIpContext().SrcIpAddrs = []string{address}
conn.GetContext().GetIpContext().DstRoutes = []*networkservice.Route{
{
Prefix: address,
Prefix: address,
NextHop: n.pool.selfAddress().IP.String(),
},
{
Prefix: prefix,
Prefix: prefix,
NextHop: n.pool.selfAddress().IP.String(),
},
}

Expand Down
13 changes: 7 additions & 6 deletions pkg/networkservice/connectioncontext/ipcontext/vl3/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,18 @@ func (v *vl3Server) Request(ctx context.Context, request *networkservice.Network
storeAddress(ctx, srcNet.String())
}

addRoute(&ipContext.SrcRoutes, v.pool.selfAddress().String())
addRoute(&ipContext.SrcRoutes, v.pool.selfPrefix().String())
addRoute(&ipContext.SrcRoutes, v.pool.selfAddress().String(), v.pool.selfAddress().IP.String())
addRoute(&ipContext.SrcRoutes, v.pool.selfPrefix().String(), v.pool.selfAddress().IP.String())
for _, srcAddr := range ipContext.SrcIpAddrs {
addRoute(&ipContext.DstRoutes, srcAddr)
addRoute(&ipContext.DstRoutes, srcAddr, "")
}
addAddr(&ipContext.DstIpAddrs, v.pool.selfAddress().String())

conn.GetContext().IpContext = ipContext

resp, err := next.Server(ctx).Request(ctx, request)
if err == nil {
addRoute(&resp.GetContext().GetIpContext().SrcRoutes, v.pool.globalIPNet().String())
addRoute(&resp.GetContext().GetIpContext().SrcRoutes, v.pool.globalIPNet().String(), v.pool.selfAddress().IP.String())
}
return resp, err
}
Expand All @@ -106,14 +106,15 @@ func (v *vl3Server) Close(ctx context.Context, conn *networkservice.Connection)
return next.Server(ctx).Close(ctx, conn)
}

func addRoute(routes *[]*networkservice.Route, prefix string) {
func addRoute(routes *[]*networkservice.Route, prefix, nextHop string) {
for _, route := range *routes {
if route.Prefix == prefix {
return
}
}
*routes = append(*routes, &networkservice.Route{
Prefix: prefix,
Prefix: prefix,
NextHop: nextHop,
})
}

Expand Down

0 comments on commit 6abdf1e

Please sign in to comment.