aboutsummaryrefslogtreecommitdiff
path: root/pkg/ipstack
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/ipstack')
-rw-r--r--pkg/ipstack/ipstack.go41
1 files changed, 20 insertions, 21 deletions
diff --git a/pkg/ipstack/ipstack.go b/pkg/ipstack/ipstack.go
index d8db8d2..6c2330d 100644
--- a/pkg/ipstack/ipstack.go
+++ b/pkg/ipstack/ipstack.go
@@ -15,16 +15,16 @@ import (
)
const (
- MAX_IP_PACKET_SIZE = 1400
- LOCAL_COST uint32 = 0
- STATIC_COST uint32 = 4294967295 // 2^32 - 1
- MaxEntries = 64
- INFINITY = 16
- SIZE_OF_RIP_ENTRY = 12
- RIP_PROTOCOL = 200
- TEST_PROTOCOL = 0
- SIZE_OF_RIP_HEADER = 4
- MAX_TIMEOUT = 12
+ MAX_IP_PACKET_SIZE = 1400
+ LOCAL_COST uint32 = 0
+ STATIC_COST uint32 = 4294967295 // 2^32 - 1
+ MaxEntries = 64
+ INFINITY = 16
+ SIZE_OF_RIP_ENTRY = 12
+ RIP_PROTOCOL = 200
+ TEST_PROTOCOL = 0
+ SIZE_OF_RIP_HEADER = 4
+ MAX_TIMEOUT = 12
)
// STRUCTS ---------------------------------------------------------------------
@@ -33,7 +33,7 @@ type Interface struct {
IpPrefix netip.Prefix
UdpAddr netip.AddrPort
- RecvSocket net.UDPConn
+ Socket net.UDPConn
SocketChannel chan bool
State bool
}
@@ -112,13 +112,13 @@ func Initialize(lnxFilePath string) error {
Name: iface.Name,
IpPrefix: prefix,
UdpAddr: iface.UDPAddr,
- RecvSocket: net.UDPConn{},
+ Socket: net.UDPConn{},
SocketChannel: make(chan bool),
State: true,
}
// create the UDP listener
- err := createUDPListener(iface.UDPAddr, &i.RecvSocket)
+ err := createUDPListener(iface.UDPAddr, &i.Socket)
if err != nil {
return errors.WithMessage(err, "Error creating UDP socket for interface->\t"+iface.Name)
}
@@ -177,7 +177,7 @@ func Initialize(lnxFilePath string) error {
// defines the go routine that listens on the UDP socket
func InterfaceListenerRoutine(i *Interface) {
// decompose the interface
- socket := i.RecvSocket
+ socket := i.Socket
signal := i.SocketChannel
// booleans to control listening routine
@@ -377,7 +377,7 @@ func CleanUp() {
close(iface.SocketChannel)
}
// close the UDP FD
- err := iface.RecvSocket.Close()
+ err := iface.Socket.Close()
if err != nil {
continue
}
@@ -463,7 +463,7 @@ func SendIP(src *netip.Addr, dest *Neighbor, protocolNum int, message []byte, de
// TODO: make this faster by removing call
// send the packet
- bytesWritten, err := iface.RecvSocket.WriteToUDP(bytesToSend, sendAddr)
+ bytesWritten, err := iface.Socket.WriteToUDP(bytesToSend, sendAddr)
if err != nil {
fmt.Println("Error writing to UDP socket")
return -1, errors.WithMessage(err, "Error writing to UDP socket")
@@ -472,14 +472,13 @@ func SendIP(src *netip.Addr, dest *Neighbor, protocolNum int, message []byte, de
return bytesWritten, nil
}
-
// RecvIP receives an IP packet from a source
func RecvIP(iface *Interface, isOpen *bool) error {
buffer := make([]byte, MAX_IP_PACKET_SIZE) // TODO: fix wording
// Read on the UDP port
// fmt.Println("wating to read from UDP socket")
- _, _, err := iface.RecvSocket.ReadFromUDP(buffer)
+ _, _, err := iface.Socket.ReadFromUDP(buffer)
if err != nil {
return err
}
@@ -598,13 +597,13 @@ func RecvIP(iface *Interface, isOpen *bool) error {
// creates a byte array that represents a RIP message
func makeRipMessage(command uint16, entries []RIPEntry) []byte {
- if command == 1 { // request message
+ if command == 1 { // request message
buf := make([]byte, SIZE_OF_RIP_HEADER)
binary.BigEndian.PutUint16(buf[0:2], command)
binary.BigEndian.PutUint16(buf[2:4], uint16(0))
return buf
}
-
+
// command == 2, response message
// create the buffer
@@ -951,4 +950,4 @@ func LongestPrefix(src netip.Addr) (Hop, error) {
}
}
return Hop{}, errors.Errorf("No route to ip %s on table.", src)
-} \ No newline at end of file
+}