summaryrefslogtreecommitdiffhomepage
path: root/packet/constant.go
diff options
context:
space:
mode:
authorISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>2015-08-10 01:25:18 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2015-08-12 08:04:31 +0900
commit5c066cc6a64b03126a737fb41954a62bae762806 (patch)
tree9c7c36561a75f3f4948bfd5ab1ae06a289a42c06 /packet/constant.go
parent163a9338fb13b10872889406079be95322cd0f46 (diff)
bgp/cli: support flowspec (RFC5575)
draft-ietf-idr-flowspec-redirect-rt-bis-05 is also implmented. TODO: draft-ietf-idr-flow-spec-v6-06 Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
Diffstat (limited to 'packet/constant.go')
-rw-r--r--packet/constant.go102
1 files changed, 102 insertions, 0 deletions
diff --git a/packet/constant.go b/packet/constant.go
index 31002c1b..c8de8007 100644
--- a/packet/constant.go
+++ b/packet/constant.go
@@ -15,6 +15,11 @@
package bgp
+import (
+ "fmt"
+ "strings"
+)
+
const AS_TRANS = 23456
const BGP_PORT = 179
@@ -30,3 +35,100 @@ const (
BGP_FSM_OPENCONFIRM
BGP_FSM_ESTABLISHED
)
+
+// partially taken from http://www.iana.org/assignments/protocol-numbers/protocol-numbers.xhtml
+type Protocol int
+
+const (
+ Unknown Protocol = iota
+ ICMP = 0x01
+ IGMP = 0x02
+ TCP = 0x06
+ EGP = 0x08
+ IGP = 0x09
+ UDP = 0x11
+ RSVP = 0x2e
+ GRE = 0x2f
+ OSPF = 0x59
+ IPIP = 0x5e
+ PIM = 0x67
+ SCTP = 0x84
+)
+
+var ProtocolNameMap = map[Protocol]string{
+ Unknown: "unknown",
+ ICMP: "icmp",
+ IGMP: "igmp",
+ TCP: "tcp",
+ EGP: "egp",
+ IGP: "igp",
+ UDP: "udp",
+ RSVP: "rsvp",
+ GRE: "gre",
+ OSPF: "ospf",
+ IPIP: "ipip",
+ PIM: "pim",
+ SCTP: "sctp",
+}
+
+var ProtocolValueMap = map[string]Protocol{
+ ProtocolNameMap[ICMP]: ICMP,
+ ProtocolNameMap[IGMP]: IGMP,
+ ProtocolNameMap[TCP]: TCP,
+ ProtocolNameMap[EGP]: EGP,
+ ProtocolNameMap[IGP]: IGP,
+ ProtocolNameMap[UDP]: UDP,
+ ProtocolNameMap[RSVP]: RSVP,
+ ProtocolNameMap[GRE]: GRE,
+ ProtocolNameMap[OSPF]: OSPF,
+ ProtocolNameMap[IPIP]: IPIP,
+ ProtocolNameMap[PIM]: PIM,
+ ProtocolNameMap[SCTP]: SCTP,
+}
+
+func (p Protocol) String() string {
+ name, ok := ProtocolNameMap[p]
+ if !ok {
+ return fmt.Sprintf("%d", p)
+ }
+ return name
+}
+
+type TCPFlag int
+
+const (
+ TCP_FLAG_FIN = 0x01
+ TCP_FLAG_SYN = 0x02
+ TCP_FLAG_RST = 0x04
+ TCP_FLAG_PUSH = 0x08
+ TCP_FLAG_ACK = 0x10
+ TCP_FLAG_URGENT = 0x20
+)
+
+var TCPFlagNameMap = map[TCPFlag]string{
+ TCP_FLAG_FIN: "fin",
+ TCP_FLAG_SYN: "syn",
+ TCP_FLAG_RST: "rst",
+ TCP_FLAG_PUSH: "push",
+ TCP_FLAG_ACK: "ack",
+ TCP_FLAG_URGENT: "urgent",
+}
+
+var TCPFlagValueMap = map[string]TCPFlag{
+ TCPFlagNameMap[TCP_FLAG_FIN]: TCP_FLAG_FIN,
+ TCPFlagNameMap[TCP_FLAG_SYN]: TCP_FLAG_SYN,
+ TCPFlagNameMap[TCP_FLAG_RST]: TCP_FLAG_RST,
+ TCPFlagNameMap[TCP_FLAG_PUSH]: TCP_FLAG_PUSH,
+ TCPFlagNameMap[TCP_FLAG_ACK]: TCP_FLAG_ACK,
+ TCPFlagNameMap[TCP_FLAG_URGENT]: TCP_FLAG_URGENT,
+}
+
+func (f TCPFlag) String() string {
+ ss := make([]string, 0, 6)
+ for k, v := range TCPFlagNameMap {
+ if f&k > 0 {
+ ss = append(ss, v)
+ }
+ }
+ return strings.Join(ss, "|")
+}