-
Notifications
You must be signed in to change notification settings - Fork 2
/
sr_router.h
141 lines (111 loc) · 3.16 KB
/
sr_router.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/*-----------------------------------------------------------------------------
* File: sr_router.h
* Date: ?
* Authors: Guido Apenzeller, Martin Casado, Virkam V.
* Contact: [email protected]
* 90904102
*---------------------------------------------------------------------------*/
#ifndef SR_ROUTER_H
#define SR_ROUTER_H
#include <netinet/in.h>
#include <sys/time.h>
#include <stdio.h>
#include "sr_protocol.h"
#ifdef VNL
#include "vnlconn.h"
#endif
#ifndef TCP
#define TCP 6
#endif
#ifndef UDP
#define UDP 17
#endif
#ifndef ARPC_TIMEOUT
#define ARPC_TIMEOUT 15
#endif
#ifndef ARPQ_MAXREQ
#define ARPQ_MAXREQ 5
#endif
#ifndef arp_broadcast_IP
#define arp_broadcast_IP 0xff
#endif
#ifndef ICMP_HDR_LEN
#define ICMP_HDR_LEN 8
#endif
#ifndef ICMP_ECHO_REQ
#define ICMP_ECHO_REQ 8
#endif
#ifndef ICMP_TTL
#define ICMP_TTL 11
#endif
#ifndef ICMP_UNREACH
#define ICMP_UNREACH 3
#endif
#ifndef ICMP_HOST_UNREACH
#define ICMP_HOST_UNREACH 1
#endif
#ifndef ICMP_PORT_UNREACH
#define ICMP_PORT_UNREACH 3
#endif
#ifndef ICMP_HDR_LEN
#define ICMP_HDR_LEN 8
#endif
//used only if IP unreachable
#ifndef ICMP_DATA_LEN
#define ICMP_DATA_LEN 8
#endif
/* we dont like this debug , but what to do for varargs ? */
#ifdef _DEBUG_
#define Debug(x, args...) printf(x, ## args)
#define DebugMAC(x) \
do { int ivyl; for(ivyl=0; ivyl<5; ivyl++) printf("%02x:", \
(unsigned char)(x[ivyl])); printf("%02x",(unsigned char)(x[5])); } while (0)
#else
#define Debug(x, args...) do{}while(0)
#define DebugMAC(x) do{}while(0)
#endif
#define INIT_TTL 255
#define PACKET_DUMP_SIZE 1024
/* forward declare */
struct sr_if;
struct sr_rt;
/* ----------------------------------------------------------------------------
* struct sr_instance
*
* Encapsulation of the state for a single virtual router.
*
* -------------------------------------------------------------------------- */
struct sr_instance
{
int sockfd; /* socket to server */
#ifdef VNL
struct VnlConn* vc;
#endif
char user[32]; /* user name */
char host[32]; /* host name */
char template[30]; /* template name if any */
char auth_key_fn[64]; /* auth key filename */
unsigned short topo_id;
struct sockaddr_in sr_addr; /* address to server */
struct sr_if* if_list; /* list of interfaces */
struct sr_rt* routing_table; /* routing table */
FILE* logfile;
};
/* -- sr_main.c -- */
int sr_verify_routing_table(struct sr_instance* sr);
/* -- sr_vns_comm.c -- */
int sr_send_packet(struct sr_instance* , uint8_t* , unsigned int , const char*);
int sr_connect_to_server(struct sr_instance* ,unsigned short , char* );
int sr_read_from_server(struct sr_instance* );
/* -- sr_router.c -- */
void sr_init(struct sr_instance* );
void sr_handlepacket(struct sr_instance* , uint8_t * , unsigned int , char* );
/* -- sr_if.c -- */
void sr_add_interface(struct sr_instance* , const char* );
void sr_set_ether_ip(struct sr_instance* , uint32_t );
void sr_set_ether_addr(struct sr_instance* , const unsigned char* );
void sr_print_if_list(struct sr_instance* );
/* -- sr_router.c --
void arp_reqeust_packet(struct sr_arphdr *arp_hdr, uint32_t sr_ip, unsigned char *sr_hw_addr, uint32_t dest_ip);
*/
#endif /* SR_ROUTER_H */