Skip to content

Commit

Permalink
Merge pull request #1 from dj-nlx/v6
Browse files Browse the repository at this point in the history
Initial NAT64 and NAT46 support
  • Loading branch information
PacketCrunch authored Dec 11, 2022
2 parents 64bab20 + 93ae6ab commit 0e8ae0e
Show file tree
Hide file tree
Showing 10 changed files with 242 additions and 158 deletions.
32 changes: 17 additions & 15 deletions api/loxinlp/nlp.go
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,7 @@ func AddAddr(addr nlp.Addr, link nlp.Link) int {
name := attrs.Name
ipStr := (addr.IPNet).String()

ret, err := hooks.NetIpv4AddrAdd(&cmn.Ipv4AddrMod{Dev: name, IP: ipStr})
ret, err := hooks.NetAddrAdd(&cmn.IpAddrMod{Dev: name, IP: ipStr})
if err != nil {
tk.LogIt(tk.LogError, "[NLP] IPv4 Address %v Port %v failed %v\n", ipStr, name, err)
ret = -1
Expand Down Expand Up @@ -861,8 +861,9 @@ func AddNeigh(neigh nlp.Neigh, link nlp.Link) int {
}
copy(mac[:], neigh.HardwareAddr[:6])

if neigh.Family == unix.AF_INET {
ret, err = hooks.NetNeighv4Add(&cmn.Neighv4Mod{IP: neigh.IP, LinkIndex: neigh.LinkIndex,
if neigh.Family == unix.AF_INET ||
neigh.Family == unix.AF_INET6 {
ret, err = hooks.NetNeighAdd(&cmn.NeighMod{IP: neigh.IP, LinkIndex: neigh.LinkIndex,
State: neigh.State,
HardwareAddr: neigh.HardwareAddr})
if err != nil {
Expand Down Expand Up @@ -944,9 +945,10 @@ func DelNeigh(neigh nlp.Neigh, link nlp.Link) int {
attrs := link.Attrs()
name := attrs.Name

if neigh.Family == unix.AF_INET {
if neigh.Family == unix.AF_INET ||
neigh.Family == unix.AF_INET6 {

ret, err = hooks.NetNeighv4Del(&cmn.Neighv4Mod{IP: neigh.IP})
ret, err = hooks.NetNeighDel(&cmn.NeighMod{IP: neigh.IP})
if err != nil {
tk.LogIt(tk.LogError, "[NLP] NH %v %v del failed\n", neigh.IP.String(), name)
ret = -1
Expand Down Expand Up @@ -1023,7 +1025,7 @@ func AddRoute(route nlp.Route) int {
} else {
ipNet = *route.Dst
}
ret, err := hooks.NetRoutev4Add(&cmn.Routev4Mod{Protocol: int(route.Protocol), Flags: route.Flags,
ret, err := hooks.NetRouteAdd(&cmn.RouteMod{Protocol: int(route.Protocol), Flags: route.Flags,
Gw: route.Gw, LinkIndex: route.LinkIndex, Dst: ipNet})
if err != nil {
if route.Gw != nil {
Expand Down Expand Up @@ -1087,7 +1089,7 @@ func DelRoute(route nlp.Route) int {
} else {
ipNet = *route.Dst
}
ret, err := hooks.NetRoutev4Del(&cmn.Routev4Mod{Dst: ipNet})
ret, err := hooks.NetRouteDel(&cmn.RouteMod{Dst: ipNet})
if err != nil {
if route.Gw != nil {
tk.LogIt(tk.LogError, "[NLP] RT %s via %s delete failed-%s\n", ipNet.String(),
Expand Down Expand Up @@ -1123,21 +1125,21 @@ func AUWorkSingle(m nlp.AddrUpdate) int {
attrs := link.Attrs()
name := attrs.Name
if m.NewAddr {
_, err := hooks.NetIpv4AddrAdd(&cmn.Ipv4AddrMod{Dev: name, IP: m.LinkAddress.String()})
_, err := hooks.NetAddrAdd(&cmn.IpAddrMod{Dev: name, IP: m.LinkAddress.String()})
if err != nil {
tk.LogIt(tk.LogInfo, "[NLP] IPv4 Address %v Port %v add failed\n", m.LinkAddress.String(), name)
tk.LogIt(tk.LogInfo, "[NLP] Address %v Port %v add failed\n", m.LinkAddress.String(), name)
fmt.Println(err)
} else {
tk.LogIt(tk.LogInfo, "[NLP] IPv4 Address %v Port %v added\n", m.LinkAddress.String(), name)
tk.LogIt(tk.LogInfo, "[NLP] Address %v Port %v added\n", m.LinkAddress.String(), name)
}

} else {
_, err := hooks.NetIpv4AddrDel(&cmn.Ipv4AddrMod{Dev: name, IP: m.LinkAddress.String()})
_, err := hooks.NetAddrDel(&cmn.IpAddrMod{Dev: name, IP: m.LinkAddress.String()})
if err != nil {
tk.LogIt(tk.LogInfo, "[NLP] IPv4 Address %v Port %v delete failed\n", m.LinkAddress.String(), name)
tk.LogIt(tk.LogInfo, "[NLP] Address %v Port %v delete failed\n", m.LinkAddress.String(), name)
fmt.Println(err)
} else {
tk.LogIt(tk.LogInfo, "[NLP] IPv4 Address %v Port %v deleted\n", m.LinkAddress.String(), name)
tk.LogIt(tk.LogInfo, "[NLP] Address %v Port %v deleted\n", m.LinkAddress.String(), name)
}
}

Expand Down Expand Up @@ -1287,7 +1289,7 @@ func NlpGet(ch chan bool) int {
}
}

addrs, err := nlp.AddrList(link, nlp.FAMILY_V4)
addrs, err := nlp.AddrList(link, nlp.FAMILY_ALL)
if err != nil {
tk.LogIt(tk.LogError, "[NLP] Error getting address list %v for intf %s\n",
err, link.Attrs().Name)
Expand Down Expand Up @@ -1316,7 +1318,7 @@ func NlpGet(ch chan bool) int {
}

/* Get Routes */
routes, err := nlp.RouteList(link, nlp.FAMILY_V4)
routes, err := nlp.RouteList(link, nlp.FAMILY_ALL)
if err != nil {
tk.LogIt(tk.LogError, "[NLP] Error getting route list %v\n", err)
}
Expand Down
2 changes: 1 addition & 1 deletion api/restapi/handler/ipv4address.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func ConfigDeleteIPv4Address(params operations.DeleteConfigIpv4addressIPAddressM

func ConfigGetIPv4Address(params operations.GetConfigIpv4addressAllParams) middleware.Responder {
tk.LogIt(tk.LogDebug, "[API] IPv4 address %s API called. url : %s\n", params.HTTPRequest.Method, params.HTTPRequest.URL)
res, _ := ApiHooks.NetIpv4AddrGet()
res, _ := ApiHooks.NetAddrGet()
var result []*models.IPV4AddressGetEntry
result = make([]*models.IPV4AddressGetEntry, 0)
for _, ipaddrs := range res {
Expand Down
2 changes: 1 addition & 1 deletion api/restapi/handler/neighbor.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func ConfigDeleteNeighbor(params operations.DeleteConfigNeighborIPAddressDevIfNa

func ConfigGetNeighbor(params operations.GetConfigNeighborAllParams) middleware.Responder {
tk.LogIt(tk.LogDebug, "[API] IPv4 Neighbor %s API called. url : %s\n", params.HTTPRequest.Method, params.HTTPRequest.URL)
res, _ := ApiHooks.NetNeighv4Get()
res, _ := ApiHooks.NetNeighGet()
var result []*models.NeighborEntry
result = make([]*models.NeighborEntry, 0)
for _, neighbor := range res {
Expand Down
2 changes: 1 addition & 1 deletion api/restapi/handler/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func ConfigDeleteRoute(params operations.DeleteConfigRouteDestinationIPNetIPAddr

func ConfigGetRoute(params operations.GetConfigRouteAllParams) middleware.Responder {
tk.LogIt(tk.LogDebug, "[API] Route %s API called. url : %s\n", params.HTTPRequest.Method, params.HTTPRequest.URL)
res, _ := ApiHooks.NetRoutev4Get()
res, _ := ApiHooks.NetRouteGet()
var result []*models.RouteGetEntry
result = make([]*models.RouteGetEntry, 0)
for _, route := range res {
Expand Down
38 changes: 19 additions & 19 deletions common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,16 +278,16 @@ type FdbMod struct {
Type int
}

// Ipv4AddrMod - Info about an ip address
type Ipv4AddrMod struct {
// IpAddrMod - Info about an ip address
type IpAddrMod struct {
// Dev - name of the related device
Dev string
// IP - Actual IP address
IP string
}

// Neighv4Mod - Info about an neighbor
type Neighv4Mod struct {
// NeighMod - Info about an neighbor
type NeighMod struct {
// IP - The IP address
IP net.IP
// LinkIndex - OS allocated index
Expand All @@ -298,8 +298,8 @@ type Neighv4Mod struct {
HardwareAddr net.HardwareAddr
}

// Ipv4AddrGet - Info about an ip addresses
type Ipv4AddrGet struct {
// IpAddrGet - Info about an ip addresses
type IpAddrGet struct {
// Dev - name of the related device
Dev string
// IP - Actual IP address
Expand All @@ -316,8 +316,8 @@ type RouteGetEntryStatistic struct {
Packets int
}

// Routev4Get - Info about an route
type Routev4Get struct {
// RouteGet - Info about an route
type RouteGet struct {
// Protocol - Protocol type
Protocol int
// Flags - flag type
Expand All @@ -336,8 +336,8 @@ type Routev4Get struct {
Sync DpStatusT
}

// Routev4Mod - Info about a route
type Routev4Mod struct {
// RouteMod - Info about a route
type RouteMod struct {
// Protocol - Protocol type
Protocol int
// Flags - flag type
Expand Down Expand Up @@ -687,15 +687,15 @@ type NetHookInterface interface {
NetVlanPortDel(*VlanPortMod) (int, error)
NetFdbAdd(*FdbMod) (int, error)
NetFdbDel(*FdbMod) (int, error)
NetIpv4AddrGet() ([]Ipv4AddrGet, error)
NetIpv4AddrAdd(*Ipv4AddrMod) (int, error)
NetIpv4AddrDel(*Ipv4AddrMod) (int, error)
NetNeighv4Get() ([]Neighv4Mod, error)
NetNeighv4Add(*Neighv4Mod) (int, error)
NetNeighv4Del(*Neighv4Mod) (int, error)
NetRoutev4Get() ([]Routev4Get, error)
NetRoutev4Add(*Routev4Mod) (int, error)
NetRoutev4Del(*Routev4Mod) (int, error)
NetAddrGet() ([]IpAddrGet, error)
NetAddrAdd(*IpAddrMod) (int, error)
NetAddrDel(*IpAddrMod) (int, error)
NetNeighGet() ([]NeighMod, error)
NetNeighAdd(*NeighMod) (int, error)
NetNeighDel(*NeighMod) (int, error)
NetRouteGet() ([]RouteGet, error)
NetRouteAdd(*RouteMod) (int, error)
NetRouteDel(*RouteMod) (int, error)
NetLbRuleAdd(*LbRuleMod) (int, error)
NetLbRuleDel(*LbRuleMod) (int, error)
NetLbRuleGet() ([]LbRuleMod, error)
Expand Down
34 changes: 17 additions & 17 deletions loxinet/apiclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,38 +141,38 @@ func (*NetAPIStruct) NetVlanPortDel(vm *cmn.VlanPortMod) (int, error) {
}

// NetIpv4AddrGet - Get an IPv4 Address info from loxinet
func (*NetAPIStruct) NetIpv4AddrGet() ([]cmn.Ipv4AddrGet, error) {
func (*NetAPIStruct) NetAddrGet() ([]cmn.IpAddrGet, error) {
// There is no locking requirement for this operation
ret := mh.zr.L3.IfaGet()
return ret, nil
}

// NetIpv4AddrAdd - Add an ipv4 address in loxinet
func (*NetAPIStruct) NetIpv4AddrAdd(am *cmn.Ipv4AddrMod) (int, error) {
// NetAddrAdd - Add an ipv4 address in loxinet
func (*NetAPIStruct) NetAddrAdd(am *cmn.IpAddrMod) (int, error) {
mh.mtx.Lock()
defer mh.mtx.Unlock()

ret, err := mh.zr.L3.IfaAdd(am.Dev, am.IP)
return ret, err
}

// NetIpv4AddrDel - Delete an ipv4 address in loxinet
func (*NetAPIStruct) NetIpv4AddrDel(am *cmn.Ipv4AddrMod) (int, error) {
// NetAddrDel - Delete an ipv4 address in loxinet
func (*NetAPIStruct) NetAddrDel(am *cmn.IpAddrMod) (int, error) {
mh.mtx.Lock()
defer mh.mtx.Unlock()

ret, err := mh.zr.L3.IfaDelete(am.Dev, am.IP)
return ret, err
}

// NetNeighv4Get - Get a ipv4 neighbor in loxinet
func (*NetAPIStruct) NetNeighv4Get() ([]cmn.Neighv4Mod, error) {
// NetNeighGet - Get a neighbor in loxinet
func (*NetAPIStruct) NetNeighGet() ([]cmn.NeighMod, error) {
ret, err := mh.zr.Nh.NeighGet()
return ret, err
}

// NetNeighv4Add - Add a ipv4 neighbor in loxinet
func (*NetAPIStruct) NetNeighv4Add(nm *cmn.Neighv4Mod) (int, error) {
// NetNeighAdd - Add a neighbor in loxinet
func (*NetAPIStruct) NetNeighAdd(nm *cmn.NeighMod) (int, error) {
mh.mtx.Lock()
defer mh.mtx.Unlock()

Expand All @@ -186,8 +186,8 @@ func (*NetAPIStruct) NetNeighv4Add(nm *cmn.Neighv4Mod) (int, error) {
return 0, nil
}

// NetNeighv4Del - Delete a ipv4 neighbor in loxinet
func (*NetAPIStruct) NetNeighv4Del(nm *cmn.Neighv4Mod) (int, error) {
// NetNeighDel - Delete a neighbor in loxinet
func (*NetAPIStruct) NetNeighDel(nm *cmn.NeighMod) (int, error) {
mh.mtx.Lock()
defer mh.mtx.Unlock()

Expand Down Expand Up @@ -215,15 +215,15 @@ func (*NetAPIStruct) NetFdbDel(fm *cmn.FdbMod) (int, error) {
return ret, err
}

// NetRoutev4Get - Get Route info from loxinet
func (*NetAPIStruct) NetRoutev4Get() ([]cmn.Routev4Get, error) {
// NetRouteGet - Get Route info from loxinet
func (*NetAPIStruct) NetRouteGet() ([]cmn.RouteGet, error) {
// There is no locking requirement for this operation
ret, _ := mh.zr.Rt.RouteGet()
return ret, nil
}

// NetRoutev4Add - Add an ipv4 route in loxinet
func (*NetAPIStruct) NetRoutev4Add(rm *cmn.Routev4Mod) (int, error) {
// NetRouteAdd - Add a route in loxinet
func (*NetAPIStruct) NetRouteAdd(rm *cmn.RouteMod) (int, error) {
var ret int
var err error

Expand All @@ -241,8 +241,8 @@ func (*NetAPIStruct) NetRoutev4Add(rm *cmn.Routev4Mod) (int, error) {
return ret, err
}

// NetRoutev4Del - Delete an ipv4 route in loxinet
func (*NetAPIStruct) NetRoutev4Del(rm *cmn.Routev4Mod) (int, error) {
// NetRouteDel - Delete a route in loxinet
func (*NetAPIStruct) NetRouteDel(rm *cmn.RouteMod) (int, error) {
mh.mtx.Lock()
defer mh.mtx.Unlock()

Expand Down
Loading

0 comments on commit 0e8ae0e

Please sign in to comment.