Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
bio-rd
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
danet
bio-rd
Commits
d26b4573
Commit
d26b4573
authored
6 years ago
by
Daniel Czerwonk
Browse files
Options
Downloads
Patches
Plain Diff
fixed typo, removed boilerplate code
parent
29a9e629
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
protocols/bgp/packet/path_attributes.go
+22
-61
22 additions, 61 deletions
protocols/bgp/packet/path_attributes.go
protocols/bgp/packet/path_attributes_test.go
+3
-3
3 additions, 3 deletions
protocols/bgp/packet/path_attributes_test.go
with
25 additions
and
64 deletions
protocols/bgp/packet/path_attributes.go
+
22
−
61
View file @
d26b4573
...
@@ -180,41 +180,15 @@ func (pa *PathAttribute) decodeASPath(buf *bytes.Buffer) error {
...
@@ -180,41 +180,15 @@ func (pa *PathAttribute) decodeASPath(buf *bytes.Buffer) error {
}
}
func
(
pa
*
PathAttribute
)
decodeNextHop
(
buf
*
bytes
.
Buffer
)
error
{
func
(
pa
*
PathAttribute
)
decodeNextHop
(
buf
*
bytes
.
Buffer
)
error
{
addr
:=
[
4
]
byte
{}
return
pa
.
decodeUint32
(
buf
,
"next hop"
)
p
:=
uint16
(
0
)
n
,
err
:=
buf
.
Read
(
addr
[
:
])
if
err
!=
nil
{
return
err
}
if
n
!=
4
{
return
fmt
.
Errorf
(
"Unable to read next hop: buf.Read read %d bytes"
,
n
)
}
pa
.
Value
=
fourBytesToUint32
(
addr
)
p
+=
4
return
dumpNBytes
(
buf
,
pa
.
Length
-
p
)
}
}
func
(
pa
*
PathAttribute
)
decodeMED
(
buf
*
bytes
.
Buffer
)
error
{
func
(
pa
*
PathAttribute
)
decodeMED
(
buf
*
bytes
.
Buffer
)
error
{
med
,
err
:=
pa
.
decodeUint32
(
buf
)
return
pa
.
decodeUint32
(
buf
,
"MED"
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"Unable to decode MED: %v"
,
err
)
}
pa
.
Value
=
uint32
(
med
)
return
nil
}
}
func
(
pa
*
PathAttribute
)
decodeLocalPref
(
buf
*
bytes
.
Buffer
)
error
{
func
(
pa
*
PathAttribute
)
decodeLocalPref
(
buf
*
bytes
.
Buffer
)
error
{
lpref
,
err
:=
pa
.
decodeUint32
(
buf
)
return
pa
.
decodeUint32
(
buf
,
"local pref"
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"Unable to decode local pref: %v"
,
err
)
}
pa
.
Value
=
uint32
(
lpref
)
return
nil
}
}
func
(
pa
*
PathAttribute
)
decodeAggregator
(
buf
*
bytes
.
Buffer
)
error
{
func
(
pa
*
PathAttribute
)
decodeAggregator
(
buf
*
bytes
.
Buffer
)
error
{
...
@@ -273,19 +247,19 @@ func (pa *PathAttribute) decodeLargeCommunities(buf *bytes.Buffer) error {
...
@@ -273,19 +247,19 @@ func (pa *PathAttribute) decodeLargeCommunities(buf *bytes.Buffer) error {
for
i
:=
uint16
(
0
);
i
<
count
;
i
++
{
for
i
:=
uint16
(
0
);
i
<
count
;
i
++
{
com
:=
LargeCommunity
{}
com
:=
LargeCommunity
{}
v
,
err
:=
read4BytesAsUin32
(
buf
)
v
,
err
:=
read4BytesAsUin
t
32
(
buf
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
com
.
GlobalAdministrator
=
v
com
.
GlobalAdministrator
=
v
v
,
err
=
read4BytesAsUin32
(
buf
)
v
,
err
=
read4BytesAsUin
t
32
(
buf
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
com
.
DataPart1
=
v
com
.
DataPart1
=
v
v
,
err
=
read4BytesAsUin32
(
buf
)
v
,
err
=
read4BytesAsUin
t
32
(
buf
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
@@ -301,22 +275,27 @@ func (pa *PathAttribute) decodeLargeCommunities(buf *bytes.Buffer) error {
...
@@ -301,22 +275,27 @@ func (pa *PathAttribute) decodeLargeCommunities(buf *bytes.Buffer) error {
}
}
func
(
pa
*
PathAttribute
)
decodeAS4Path
(
buf
*
bytes
.
Buffer
)
error
{
func
(
pa
*
PathAttribute
)
decodeAS4Path
(
buf
*
bytes
.
Buffer
)
error
{
as4Path
,
err
:=
pa
.
decodeUint32
(
buf
)
return
pa
.
decodeUint32
(
buf
,
"AS4Path"
)
}
func
(
pa
*
PathAttribute
)
decodeAS4Aggregator
(
buf
*
bytes
.
Buffer
)
error
{
return
pa
.
decodeUint32
(
buf
,
"AS4Aggregator"
)
}
func
(
pa
*
PathAttribute
)
decodeUint32
(
buf
*
bytes
.
Buffer
,
attrName
string
)
error
{
v
,
err
:=
read4BytesAsUint32
(
buf
)
if
err
!=
nil
{
if
err
!=
nil
{
return
fmt
.
Errorf
(
"Unable to decode
AS4Path: %v"
,
err
)
return
fmt
.
Errorf
(
"Unable to decode
%s: %v"
,
attrName
,
err
)
}
}
pa
.
Value
=
as4Path
pa
.
Value
=
v
return
nil
}
func
(
pa
*
PathAttribute
)
decodeAS4Aggregator
(
buf
*
bytes
.
Buffer
)
error
{
p
:=
uint16
(
4
)
as4Aggregator
,
err
:
=
pa
.
decodeUint32
(
buf
)
err
=
dumpNBytes
(
buf
,
pa
.
Length
-
p
)
if
err
!=
nil
{
if
err
!=
nil
{
return
fmt
.
Errorf
(
"
Unable to decode AS4Aggregator
: %v"
,
err
)
return
fmt
.
Errorf
(
"
dumpNBytes failed
: %v"
,
err
)
}
}
pa
.
Value
=
as4Aggregator
return
nil
return
nil
}
}
...
@@ -340,24 +319,6 @@ func (pa *PathAttribute) setLength(buf *bytes.Buffer) (int, error) {
...
@@ -340,24 +319,6 @@ func (pa *PathAttribute) setLength(buf *bytes.Buffer) (int, error) {
return
bytesRead
,
nil
return
bytesRead
,
nil
}
}
func
(
pa
*
PathAttribute
)
decodeUint32
(
buf
*
bytes
.
Buffer
)
(
uint32
,
error
)
{
var
v
uint32
p
:=
uint16
(
0
)
err
:=
decode
(
buf
,
[]
interface
{}{
&
v
})
if
err
!=
nil
{
return
0
,
err
}
p
+=
4
err
=
dumpNBytes
(
buf
,
pa
.
Length
-
p
)
if
err
!=
nil
{
return
0
,
fmt
.
Errorf
(
"dumpNBytes failed: %v"
,
err
)
}
return
v
,
nil
}
func
(
pa
*
PathAttribute
)
ASPathString
()
(
ret
string
)
{
func
(
pa
*
PathAttribute
)
ASPathString
()
(
ret
string
)
{
for
_
,
p
:=
range
pa
.
Value
.
(
ASPath
)
{
for
_
,
p
:=
range
pa
.
Value
.
(
ASPath
)
{
if
p
.
Type
==
ASSet
{
if
p
.
Type
==
ASSet
{
...
@@ -670,14 +631,14 @@ func fourBytesToUint32(address [4]byte) uint32 {
...
@@ -670,14 +631,14 @@ func fourBytesToUint32(address [4]byte) uint32 {
return
uint32
(
address
[
0
])
<<
24
+
uint32
(
address
[
1
])
<<
16
+
uint32
(
address
[
2
])
<<
8
+
uint32
(
address
[
3
])
return
uint32
(
address
[
0
])
<<
24
+
uint32
(
address
[
1
])
<<
16
+
uint32
(
address
[
2
])
<<
8
+
uint32
(
address
[
3
])
}
}
func
read4BytesAsUin32
(
buf
*
bytes
.
Buffer
)
(
uint32
,
error
)
{
func
read4BytesAsUin
t
32
(
buf
*
bytes
.
Buffer
)
(
uint32
,
error
)
{
b
:=
[
4
]
byte
{}
b
:=
[
4
]
byte
{}
n
,
err
:=
buf
.
Read
(
b
[
:
])
n
,
err
:=
buf
.
Read
(
b
[
:
])
if
err
!=
nil
{
if
err
!=
nil
{
return
0
,
err
return
0
,
err
}
}
if
n
!=
4
{
if
n
!=
4
{
return
0
,
fmt
.
Errorf
(
"Unable to read as uint32
: buf.Read read %d bytes
"
,
n
)
return
0
,
fmt
.
Errorf
(
"Unable to read as uint32
. Expected 4 bytes but got only %d
"
,
n
)
}
}
return
fourBytesToUint32
(
b
),
nil
return
fourBytesToUint32
(
b
),
nil
...
...
This diff is collapsed.
Click to expand it.
protocols/bgp/packet/path_attributes_test.go
+
3
−
3
View file @
d26b4573
...
@@ -724,7 +724,7 @@ func TestSetLength(t *testing.T) {
...
@@ -724,7 +724,7 @@ func TestSetLength(t *testing.T) {
}
}
}
}
func
Test
Decode
Uint32
(
t
*
testing
.
T
)
{
func
Test
Read4BytesAs
Uint32
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
tests
:=
[]
struct
{
name
string
name
string
input
[]
byte
input
[]
byte
...
@@ -763,7 +763,7 @@ func TestDecodeUint32(t *testing.T) {
...
@@ -763,7 +763,7 @@ func TestDecodeUint32(t *testing.T) {
pa
:=
&
PathAttribute
{
pa
:=
&
PathAttribute
{
Length
:
l
,
Length
:
l
,
}
}
res
,
err
:=
pa
.
decodeUint32
(
bytes
.
NewBuffer
(
test
.
input
))
err
:=
pa
.
decodeUint32
(
bytes
.
NewBuffer
(
test
.
input
)
,
"test"
)
if
test
.
wantFail
{
if
test
.
wantFail
{
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -778,7 +778,7 @@ func TestDecodeUint32(t *testing.T) {
...
@@ -778,7 +778,7 @@ func TestDecodeUint32(t *testing.T) {
continue
continue
}
}
assert
.
Equal
(
t
,
test
.
expected
,
res
)
assert
.
Equal
(
t
,
test
.
expected
,
pa
.
Value
)
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment