summaryrefslogtreecommitdiffhomepage
path: root/packet
diff options
context:
space:
mode:
Diffstat (limited to 'packet')
-rw-r--r--packet/bgp/bgp.go30
-rw-r--r--packet/bgp/constant.go36
2 files changed, 33 insertions, 33 deletions
diff --git a/packet/bgp/bgp.go b/packet/bgp/bgp.go
index 7ccebf88..dd924624 100644
--- a/packet/bgp/bgp.go
+++ b/packet/bgp/bgp.go
@@ -2827,24 +2827,24 @@ func parseTcpFlagCmd(myCmd string) ([][2]int, error) {
for index < len(myCmd) {
myCmdChar := myCmd[index : index+1]
switch myCmdChar {
- case TCPFlagOpNameMap[TCP_FLAG_OP_MATCH]:
- if bit := TCPFlagOpValueMap[myCmdChar]; bit&TCPFlagOp(operatorValue[0]) == 0 {
+ case BitmaskFlagOpNameMap[BITMASK_FLAG_OP_MATCH]:
+ if bit := BitmaskFlagOpValueMap[myCmdChar]; bit&BitmaskFlagOp(operatorValue[0]) == 0 {
operatorValue[0] |= int(bit)
index++
} else {
err := fmt.Errorf("Match flag appears multiple time")
return nil, err
}
- case TCPFlagOpNameMap[TCP_FLAG_OP_NOT]:
- if bit := TCPFlagOpValueMap[myCmdChar]; bit&TCPFlagOp(operatorValue[0]) == 0 {
+ case BitmaskFlagOpNameMap[BITMASK_FLAG_OP_NOT]:
+ if bit := BitmaskFlagOpValueMap[myCmdChar]; bit&BitmaskFlagOp(operatorValue[0]) == 0 {
operatorValue[0] |= int(bit)
index++
} else {
err := fmt.Errorf("Not flag appears multiple time")
return nil, err
}
- case TCPFlagOpNameMap[TCP_FLAG_OP_AND], TCPFlagOpNameMap[TCP_FLAG_OP_OR]:
- if bit := TCPFlagOpValueMap[myCmdChar]; bit&TCPFlagOp(operatorValue[0]) == 0 {
+ case BitmaskFlagOpNameMap[BITMASK_FLAG_OP_AND], BitmaskFlagOpNameMap[BITMASK_FLAG_OP_OR]:
+ if bit := BitmaskFlagOpValueMap[myCmdChar]; bit&BitmaskFlagOp(operatorValue[0]) == 0 {
tcpOperatorsFlagsValues = append(tcpOperatorsFlagsValues, operatorValue)
operatorValue[0] = int(bit)
operatorValue[1] = 0
@@ -2861,7 +2861,7 @@ func parseTcpFlagCmd(myCmd string) ([][2]int, error) {
// we loop till we reach the end of TCP flags description
// exit conditions : we reach the end of tcp flags (we find & or ' ') or we reach the end of the line
for loopIndex < len(myCmd) &&
- (myLoopChar != TCPFlagOpNameMap[TCP_FLAG_OP_AND] && myLoopChar != TCPFlagOpNameMap[TCP_FLAG_OP_OR]) {
+ (myLoopChar != BitmaskFlagOpNameMap[BITMASK_FLAG_OP_AND] && myLoopChar != BitmaskFlagOpNameMap[BITMASK_FLAG_OP_OR]) {
// we check if inspected charater is a well known tcp flag and if it doesn't appear twice
if bit, isPresent := TCPFlagValueMap[myLoopChar]; isPresent && (bit&TCPFlag(operatorValue[1]) == 0) {
operatorValue[1] |= int(bit) // we set this flag
@@ -2881,7 +2881,7 @@ func parseTcpFlagCmd(myCmd string) ([][2]int, error) {
return nil, err
}
}
- operatorValue[0] |= int(TCPFlagOpValueMap["E"])
+ operatorValue[0] |= int(BitmaskFlagOpValueMap["E"])
tcpOperatorsFlagsValues = append(tcpOperatorsFlagsValues, operatorValue)
return tcpOperatorsFlagsValues, nil
}
@@ -3530,21 +3530,21 @@ func formatProto(op int, value int) string {
func formatFlag(op int, value int) string {
var retString string
- if op&TCP_FLAG_OP_MATCH > 0 {
- retString = fmt.Sprintf("%s%s", retString, TCPFlagOpNameMap[TCP_FLAG_OP_MATCH])
+ if op&BITMASK_FLAG_OP_MATCH > 0 {
+ retString = fmt.Sprintf("%s%s", retString, BitmaskFlagOpNameMap[BITMASK_FLAG_OP_MATCH])
}
- if op&TCP_FLAG_OP_NOT > 0 {
- retString = fmt.Sprintf("%s%s", retString, TCPFlagOpNameMap[TCP_FLAG_OP_NOT])
+ if op&BITMASK_FLAG_OP_NOT > 0 {
+ retString = fmt.Sprintf("%s%s", retString, BitmaskFlagOpNameMap[BITMASK_FLAG_OP_NOT])
}
for flag, valueFlag := range TCPFlagValueMap {
if value&int(valueFlag) > 0 {
retString = fmt.Sprintf("%s%s", retString, flag)
}
}
- if op&TCP_FLAG_OP_AND > 0 {
- retString = fmt.Sprintf("%s%s", TCPFlagOpNameMap[TCP_FLAG_OP_AND], retString)
+ if op&BITMASK_FLAG_OP_AND > 0 {
+ retString = fmt.Sprintf("%s%s", BitmaskFlagOpNameMap[BITMASK_FLAG_OP_AND], retString)
} else { // default is or
- retString = fmt.Sprintf("%s%s", TCPFlagOpNameMap[TCP_FLAG_OP_OR], retString)
+ retString = fmt.Sprintf("%s%s", BitmaskFlagOpNameMap[BITMASK_FLAG_OP_OR], retString)
}
return retString
}
diff --git a/packet/bgp/constant.go b/packet/bgp/constant.go
index faa156e1..2cee1f31 100644
--- a/packet/bgp/constant.go
+++ b/packet/bgp/constant.go
@@ -128,30 +128,30 @@ var TCPFlagValueMap = map[string]TCPFlag{
TCPFlagNameMap[TCP_FLAG_ECE]: TCP_FLAG_ECE,
}
-type TCPFlagOp int
+type BitmaskFlagOp int
const (
- TCP_FLAG_OP_OR = 0x00
- TCP_FLAG_OP_AND = 0x40
- TCP_FLAG_OP_END = 0x80
- TCP_FLAG_OP_NOT = 0x02
- TCP_FLAG_OP_MATCH = 0x01
+ BITMASK_FLAG_OP_OR = 0x00
+ BITMASK_FLAG_OP_AND = 0x40
+ BITMASK_FLAG_OP_END = 0x80
+ BITMASK_FLAG_OP_NOT = 0x02
+ BITMASK_FLAG_OP_MATCH = 0x01
)
-var TCPFlagOpNameMap = map[TCPFlagOp]string{
- TCP_FLAG_OP_OR: " ",
- TCP_FLAG_OP_AND: "&",
- TCP_FLAG_OP_END: "E",
- TCP_FLAG_OP_NOT: "!",
- TCP_FLAG_OP_MATCH: "=",
+var BitmaskFlagOpNameMap = map[BitmaskFlagOp]string{
+ BITMASK_FLAG_OP_OR: " ",
+ BITMASK_FLAG_OP_AND: "&",
+ BITMASK_FLAG_OP_END: "E",
+ BITMASK_FLAG_OP_NOT: "!",
+ BITMASK_FLAG_OP_MATCH: "=",
}
-var TCPFlagOpValueMap = map[string]TCPFlagOp{
- TCPFlagOpNameMap[TCP_FLAG_OP_OR]: TCP_FLAG_OP_OR,
- TCPFlagOpNameMap[TCP_FLAG_OP_AND]: TCP_FLAG_OP_AND,
- TCPFlagOpNameMap[TCP_FLAG_OP_END]: TCP_FLAG_OP_END,
- TCPFlagOpNameMap[TCP_FLAG_OP_NOT]: TCP_FLAG_OP_NOT,
- TCPFlagOpNameMap[TCP_FLAG_OP_MATCH]: TCP_FLAG_OP_MATCH,
+var BitmaskFlagOpValueMap = map[string]BitmaskFlagOp{
+ BitmaskFlagOpNameMap[BITMASK_FLAG_OP_OR]: BITMASK_FLAG_OP_OR,
+ BitmaskFlagOpNameMap[BITMASK_FLAG_OP_AND]: BITMASK_FLAG_OP_AND,
+ BitmaskFlagOpNameMap[BITMASK_FLAG_OP_END]: BITMASK_FLAG_OP_END,
+ BitmaskFlagOpNameMap[BITMASK_FLAG_OP_NOT]: BITMASK_FLAG_OP_NOT,
+ BitmaskFlagOpNameMap[BITMASK_FLAG_OP_MATCH]: BITMASK_FLAG_OP_MATCH,
}
type DECNumOp int