-
Notifications
You must be signed in to change notification settings - Fork 0
shaftoes/router
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
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.
About
No description, website, or topics provided.
Resources
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published