MCPcopy
hub / github.com/osrg/gobgp / UpdatePathAttrs4ByteAs

Function UpdatePathAttrs4ByteAs

internal/pkg/table/message.go:96–225  ·  view source on GitHub ↗
(logger *slog.Logger, msg *bgp.BGPUpdate)

Source from the content-addressed store, hash-verified

94}
95
96func UpdatePathAttrs4ByteAs(logger *slog.Logger, msg *bgp.BGPUpdate) {
97 var asAttr *bgp.PathAttributeAsPath
98 var as4Attr *bgp.PathAttributeAs4Path
99 asAttrPos := 0
100 as4AttrPos := 0
101 for i, attr := range msg.PathAttributes {
102 switch a := attr.(type) {
103 case *bgp.PathAttributeAsPath:
104 asAttr = a
105 for j, param := range asAttr.Value {
106 as2Param, ok := param.(*bgp.AsPathParam)
107 if ok {
108 asPath := make([]uint32, 0, len(as2Param.AS))
109 for _, as := range as2Param.AS {
110 asPath = append(asPath, uint32(as))
111 }
112 as4Param := bgp.NewAs4PathParam(as2Param.Type, asPath)
113 asAttr.Value[j] = as4Param
114 }
115 }
116 asAttrPos = i
117 msg.PathAttributes[i] = asAttr
118 case *bgp.PathAttributeAs4Path:
119 as4AttrPos = i
120 as4Attr = a
121 }
122 }
123
124 if as4Attr != nil {
125 msg.PathAttributes = append(msg.PathAttributes[:as4AttrPos], msg.PathAttributes[as4AttrPos+1:]...)
126 // Adjust asAttrPos if AS4_PATH was before AS_PATH
127 // (AS4_PATH removal shifts the indices of subsequent attributes)
128 if as4AttrPos < asAttrPos {
129 asAttrPos--
130 }
131 }
132
133 if asAttr == nil || as4Attr == nil {
134 return
135 }
136
137 asLen := 0
138 asConfedLen := 0
139 asParams := make([]bgp.AsPathParamInterface, 0, len(asAttr.Value))
140 for _, param := range asAttr.Value {
141 asLen += param.ASLen()
142 switch param.GetType() {
143 case bgp.BGP_ASPATH_ATTR_TYPE_CONFED_SET:
144 asConfedLen++
145 case bgp.BGP_ASPATH_ATTR_TYPE_CONFED_SEQ:
146 asConfedLen += len(param.GetAS())
147 }
148 asParams = append(asParams, param)
149 }
150
151 as4Len := 0
152 var as4Params []bgp.AsPathParamInterface
153 if as4Attr != nil {

Calls 6

NewAs4PathParamFunction · 0.92
NewPathAttributeAsPathFunction · 0.92
ASLenMethod · 0.65
GetTypeMethod · 0.65
GetASMethod · 0.65
StringMethod · 0.65

Used in the wild real call sites across dependent graphs

searching dependent graphs…