-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathREADME.TXT
More file actions
executable file
·81 lines (49 loc) · 2.74 KB
/
README.TXT
File metadata and controls
executable file
·81 lines (49 loc) · 2.74 KB
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
ADDED FUNCTIONS:
below is an added list of functions.
sr_router.c
void handle_ip_packet(struct sr_instance* sr, uint8_t * packet, unsigned int len, char* interface);
handles all incoming IP packets
void handle_arp_packet(struct sr_instance*, uint8_t *, unsigned int, char* );
handles all incoming arp packets
void handle_arp_reply(struct sr_instance* sr, sr_arp_hdr_t* arp_request,, sr_arp_hdr_t* arp_struct);
handles are replies
sr_arp_hdr_t* construct_arp_reply(sr_arp_hdr_t* arp_request, uint8_t* mac);
constructs an arp reply given request
int send_arp_reply(struct sr_instance* sr, sr_arp_hdr_t* arp_request, struct sr_if* sending_interface);
sends an arp reply
void handle_ip_icmp(struct sr_instance* sr, uint8_t* ip_packet, char* interface);
handles incoming icmp packets
void send_ip_packet(struct sr_instance* sr,uint8_t *buf, unsigned int len);
void send_icmp_echo(struct sr_instance* sr, uint8_t* packet, uint16_t len);
sneds echo
void send_icmp_t3t11(struct sr_instance* sr, uint8_t* packet, uint16_t len, uint8_t type, uint8_t code);
sr_arpcache:
void send_arp_request(struct sr_instance* sr, uint32_t target_ip);
sr_rt:
struct sr_rt *rt_lpm(struct sr_instance* sr, uint32_t ip);
ASSUMPTIONS:
all ip headers are type4s / 20bytes long.
all ARP REQUESTS have broadcast as targer hardware address (don't check)
TTL:
For any packet destined to one of our interfaces, we do not check if the TTL >= 0. For any packet that needs to forwarded, decrement the TTL, if 0 or less, send ICMP 11, otherwise, forward. See handle_ip_packet for implementation
LONGEST PREFIX: ()
simple iteration through routing table. Consider the routing table is static and small, more complicated versions seemed useless for now.
FOREACH ROUTING TABLE ENTRY e
if e.address (bitwise and) e.mask == ip (bitwise and) e.mask
if e.mask > cur_largest_mask
cur_largest_mask = e.mask
cur_largest = e
return cur_largest
FORWARDING IP PACKETS
every IP packet sent out of any interface (including ones generated by the router) passes through send_ip_packet (sr_router.c):
1)adds ethernet header
2)looks up next_hop
3)looks up next_hop in arp cache
4)adds to queue if necessary
ARP (handle_arp_packet, handle_arp_replies in sr_router.c)
general idea: limit ARP traffic to within each physical network.
REQUESTS are only replied to if asking for an interface on the router. Are not added to cache, as instructed by piazza post.
ARP REPLIES: added to cache if target ip is the ip of interface it was recieved
ICMP
WE ONLY HANDLE ECHO REQUEST. No other incoming ICMP messages are supported.
While 'traceroute' is technically a ICMP request type, it has not seen widespread adoption so it has been ignored.