Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a C++ function (not program) to compute forwarding of a packet in an IP ro

ID: 3697591 • Letter: W

Question

Write a C++ function (not program) to compute forwarding of a packet in an IP router. The function should be named route and has three input paramaters: an IP address (a 32 bit integer) a table with three integers per entry: an IP address a subnet mask the output line to be used the number of entries in the table the function should return the output line to be used vi given the input IP address you are expected to write your own test programs The filename of your function MUST BE {your last name}_router.cc My test function is available as test_route.cc

Explanation / Answer

Assume the subnet mask specifies the CIDR prefix for the entry.

int look-up(int ipa)
out-line = default-out-line
prefix-size = 0

for each entry in look-up-table
   if ipa & entry.mask == entry.prefix and prefix-size < entry.mask.size
     prefix-size = entry.mask.size
        out-line = entry.out-line
return out-line

This is a simple algorithm, but impractically inefficient.

The function receives as an input parameter the buffer skb associated with the packet; the necessary information is inside that structure. skp->dst, the routine information, was initialized by the call to ip_route_input in ip_rcv_finish earlier in the code path.

int ip_forward(struct sk_buff * skb)

If there is no Router_Alert option in the header, or if it is present but no interested processes are running (in which case ip_call_ra_chain) return FALSE), ip_forward continues:1

if (IPCB(skb)->opt.router_alert && ip_call_ra_chain(skb))
return NET_RX_SUCCESS

if (skb->pkt_type != PACKET_HOST)
goto drop

   skb->ip_summed = CHECKSUM_NONE

   if (iph->ttl <= 1)
goto too_many_hops

rt = (struct rtable *) skb->dst;
if (opt->is_strictroute && rt->rt_dst != rt->rt_gateway)
goto sr_failed

if (skb_cow(skb, LL_RESERVED_SPACE(rt->u.dst.dev) + rt->u.dst.header_len))
goto drop

ip_decrease_ttl(iph)

if (rt->rt_flags & RTCF_DOREDIRECT && !opt->srr)
   ip_rt_send_redirect(skb)

skb->priority = rt_tos2priority(iph->tos)

return NF_HOOK(
   PF_INET, NF_IP_FORWARD, skb, skb->dev, rt->u.dst.dev, ip_forward_finish)

The packet is finally transmitted with dst_output given below:

static inline int ip_forward_finish(struct sk_buff * skb)

{

    struct ip_options * opt = &(IPCB(skb)->opt)

    IP_INC_STATUS_BH(IPSTATS_MIB_OUTFORWARDDATAGRAMS)

    if (unlikely(ipt->optlen) {
      ip_forward_options(skb)

    return dst_output(skb)

}

IP Packet Validation:

The router must check that the received packet is properly formed for the protocol before it proceeds with protocol processing. This involves checking the version number, checking the header length field (also needed to determine whether any options are present in the packet), and calculating the header checksum.2

Destination IP Address Parsing and Table Lookup:

The router performs a table lookup to determine the output port onto which to direct the packet, and the next hop to which to send the packet along this route. This is based on the destination IP address in the received packet and the subnet mask(s) of the associated table entires. The result of this lookup could imply: - A local delivery: that is, the destination addresses is one of the router's local addresses and the packet is locally delivered. - A unicast delivery: to a single output port, either to a next-hop router or to the ultimate destination station. - A multicast delivery: to a set of output ports that depends on the router's knowledge of multicast group membership. The router must also determine the maping of the destination network address to the daa link address for the output port (address resolution or ARP). This can be done either as a separate step or integrated as part of the routing lookup. - Packet Lifetime Control: The router adjusts the time-to-live (TTL) field in the packet used to prevent packets from circulating endlessly throughout the internetwork. A packet being delivered to a local address within the router is acceptable if it has any positive value of TTL. A packet being routed to output ports has its TTL value decremented as appropriate and then is rechecked to determine if it has any life before it is actually forwarded. A packet whose lifetime is exceeded is discarded by the router (and may cause an error message to be generated to the original sender). - Checksum Calculation: The IP header checksum must be recalculated due to the change in the TTL field. Fortunately, the checksum algorithm employed (a 16-bit one's complement addition of the header fields) is both commutative and associative, thereby allowing simple, differential recomputation.

    If (N matches a directly connected network address)

      Deliver datagram to D over that network link;

    Else if (the routing table contains a route for N)

      Send datagram to the next-hop address listed in the routing table;

    Else if (there exists a default route)

      Send a datagram to the default route;

    Else

      Send a forwarding error message to the originator;

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote