Skip to content

Commit 37df67c

Browse files
committed
pkg/packet/bgp: use netip for LsTLVSrv6SIDInfo
Replace net.IP with netip.Addr for LsTLVSrv6SIDInfo. Signed-off-by: FUJITA Tomonori <[email protected]>
1 parent bf6e041 commit 37df67c

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

cmd/gobgp/global.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1684,7 +1684,10 @@ func parseLsSRv6SIDNLRIType(args []string) (bgp.AddrPrefixInterface, *bgp.PathAt
16841684
}
16851685
lndTLV := bgp.NewLsTLVNodeDescriptor(lnd, bgp.LS_TLV_LOCAL_NODE_DESC)
16861686

1687-
sids, ssiLen := apiutil.StringToNetIPLsTLVSrv6SIDInfo(m["sids"])
1687+
sids, ssiLen, err := apiutil.StringToNetIPLsTLVSrv6SIDInfo(m["sids"])
1688+
if err != nil {
1689+
return nil, nil, err
1690+
}
16881691
ssi := &bgp.LsTLVSrv6SIDInfo{
16891692
LsTLV: bgp.LsTLV{
16901693
Type: bgp.LS_TLV_SRV6_SID_INFO,

pkg/apiutil/attribute.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -892,18 +892,25 @@ func UnmarshalLsPrefixDescriptor(*api.LsPrefixDescriptor) (*bgp.LsPrefixDescript
892892
return nil, nil
893893
}
894894

895-
func StringToNetIPLsTLVSrv6SIDInfo(s []string) ([]net.IP, uint16) {
896-
sids := []net.IP{}
895+
func StringToNetIPLsTLVSrv6SIDInfo(s []string) ([]netip.Addr, uint16, error) {
896+
sids := []netip.Addr{}
897897
var ssiLen uint16
898898
for _, sid := range s {
899-
sids = append(sids, net.ParseIP(sid))
899+
addr, err := netip.ParseAddr(sid)
900+
if err != nil {
901+
return nil, 0, err
902+
}
903+
sids = append(sids, addr)
900904
ssiLen += 16
901905
}
902-
return sids, ssiLen
906+
return sids, ssiLen, nil
903907
}
904908

905909
func UnmarshalLsTLVSrv6SIDInfo(ssi *api.LsSrv6SIDInformation) (*bgp.LsTLVSrv6SIDInfo, error) {
906-
sids, ssiLen := StringToNetIPLsTLVSrv6SIDInfo(ssi.Sids)
910+
sids, ssiLen, err := StringToNetIPLsTLVSrv6SIDInfo(ssi.Sids)
911+
if err != nil {
912+
return nil, err
913+
}
907914
return &bgp.LsTLVSrv6SIDInfo{
908915
LsTLV: bgp.LsTLV{
909916
Type: bgp.LS_TLV_SRV6_SID_INFO,

pkg/packet/bgp/bgp.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5993,7 +5993,7 @@ func (l *LsPrefixV6NLRI) MarshalJSON() ([]byte, error) {
59935993

59945994
type LsTLVSrv6SIDInfo struct {
59955995
LsTLV
5996-
SIDs []net.IP
5996+
SIDs []netip.Addr
59975997
}
59985998

59995999
func (l *LsTLVSrv6SIDInfo) DecodeFromBytes(data []byte) error {
@@ -6003,7 +6003,8 @@ func (l *LsTLVSrv6SIDInfo) DecodeFromBytes(data []byte) error {
60036003
}
60046004

60056005
for i := range len(sid) / 16 {
6006-
l.SIDs = append(l.SIDs, net.IP(sid[i*16:i*16+16]))
6006+
addr, _ := netip.AddrFromSlice(sid[i*16 : i*16+16])
6007+
l.SIDs = append(l.SIDs, addr)
60076008
}
60086009

60096010
return nil
@@ -6013,7 +6014,7 @@ func (l *LsTLVSrv6SIDInfo) Serialize() ([]byte, error) {
60136014
buf := []byte{}
60146015

60156016
for _, sid := range l.SIDs {
6016-
buf = append(buf, sid...)
6017+
buf = append(buf, sid.AsSlice()...)
60176018
}
60186019

60196020
return l.LsTLV.Serialize(buf)

0 commit comments

Comments
 (0)