net: cosmetic: Split struct ip_udp_hdr into ip_hdr
[pandora-u-boot.git] / net / net.c
index b488490..2bf5631 100644 (file)
--- a/net/net.c
+++ b/net/net.c
@@ -82,9 +82,7 @@
 #include "arp.h"
 #include "bootp.h"
 #include "tftp.h"
-#ifdef CONFIG_CMD_RARP
 #include "rarp.h"
-#endif
 #include "nfs.h"
 #ifdef CONFIG_STATUS_LED
 #include <status_led.h>
@@ -621,12 +619,13 @@ NetSendUDPPacket(uchar *ether, IPaddr_t dest, int dport, int sport, int len)
                pkt += NetSetEther(pkt, NetArpWaitPacketMAC, PROT_IP);
 
                NetSetIP(pkt, dest, dport, sport, len);
-               memcpy(pkt + IP_HDR_SIZE, (uchar *)NetTxPacket +
-                      (pkt - (uchar *)NetArpWaitTxPacket) + IP_HDR_SIZE, len);
+               memcpy(pkt + IP_UDP_HDR_SIZE, (uchar *)NetTxPacket +
+                      (pkt - (uchar *)NetArpWaitTxPacket) +
+                      IP_UDP_HDR_SIZE, len);
 
                /* size of the waiting packet */
                NetArpWaitTxPacketSize = (pkt - NetArpWaitTxPacket) +
-                       IP_HDR_SIZE + len;
+                       IP_UDP_HDR_SIZE + len;
 
                /* and do the ARP request */
                NetArpWaitTry = 1;
@@ -640,7 +639,7 @@ NetSendUDPPacket(uchar *ether, IPaddr_t dest, int dport, int sport, int len)
        pkt = (uchar *)NetTxPacket;
        pkt += NetSetEther(pkt, ether, PROT_IP);
        NetSetIP(pkt, dest, dport, sport, len);
-       (void) eth_send(NetTxPacket, (pkt - NetTxPacket) + IP_HDR_SIZE + len);
+       eth_send(NetTxPacket, (pkt - NetTxPacket) + IP_UDP_HDR_SIZE + len);
 
        return 0;       /* transmitted */
 }
@@ -664,7 +663,7 @@ NetSendUDPPacket(uchar *ether, IPaddr_t dest, int dport, int sport, int len)
 static struct rpc_t rpc_specimen;
 #define IP_PKTSIZE (CONFIG_NET_MAXDEFRAG + sizeof(rpc_specimen.u.reply))
 
-#define IP_MAXUDP (IP_PKTSIZE - IP_HDR_SIZE_NO_UDP)
+#define IP_MAXUDP (IP_PKTSIZE - IP_HDR_SIZE)
 
 /*
  * this is the packet being assembled, either data or frag control.
@@ -678,22 +677,22 @@ struct hole {
        u16 unused;
 };
 
-static IP_t *__NetDefragment(IP_t *ip, int *lenp)
+static struct ip_udp_hdr *__NetDefragment(struct ip_udp_hdr *ip, int *lenp)
 {
        static uchar pkt_buff[IP_PKTSIZE] __aligned(PKTALIGN);
        static u16 first_hole, total_len;
        struct hole *payload, *thisfrag, *h, *newh;
-       IP_t *localip = (IP_t *)pkt_buff;
+       struct ip_udp_hdr *localip = (struct ip_udp_hdr *)pkt_buff;
        uchar *indata = (uchar *)ip;
        int offset8, start, len, done = 0;
        u16 ip_off = ntohs(ip->ip_off);
 
        /* payload starts after IP header, this fragment is in there */
-       payload = (struct hole *)(pkt_buff + IP_HDR_SIZE_NO_UDP);
+       payload = (struct hole *)(pkt_buff + IP_HDR_SIZE);
        offset8 =  (ip_off & IP_OFFS);
        thisfrag = payload + offset8;
        start = offset8 * 8;
-       len = ntohs(ip->ip_len) - IP_HDR_SIZE_NO_UDP;
+       len = ntohs(ip->ip_len) - IP_HDR_SIZE;
 
        if (start + len > IP_MAXUDP) /* fragment extends too far */
                return NULL;
@@ -706,7 +705,7 @@ static IP_t *__NetDefragment(IP_t *ip, int *lenp)
                payload[0].prev_hole = 0;
                first_hole = 0;
                /* any IP header will work, copy the first we received */
-               memcpy(localip, ip, IP_HDR_SIZE_NO_UDP);
+               memcpy(localip, ip, IP_HDR_SIZE);
        }
 
        /*
@@ -789,16 +788,16 @@ static IP_t *__NetDefragment(IP_t *ip, int *lenp)
        }
 
        /* finally copy this fragment and possibly return whole packet */
-       memcpy((uchar *)thisfrag, indata + IP_HDR_SIZE_NO_UDP, len);
+       memcpy((uchar *)thisfrag, indata + IP_HDR_SIZE, len);
        if (!done)
                return NULL;
 
        localip->ip_len = htons(total_len);
-       *lenp = total_len + IP_HDR_SIZE_NO_UDP;
+       *lenp = total_len + IP_HDR_SIZE;
        return localip;
 }
 
-static inline IP_t *NetDefragment(IP_t *ip, int *lenp)
+static inline struct ip_udp_hdr *NetDefragment(struct ip_udp_hdr *ip, int *lenp)
 {
        u16 ip_off = ntohs(ip->ip_off);
        if (!(ip_off & (IP_OFFS | IP_FLAGS_MFRAG)))
@@ -808,7 +807,7 @@ static inline IP_t *NetDefragment(IP_t *ip, int *lenp)
 
 #else /* !CONFIG_IP_DEFRAG */
 
-static inline IP_t *NetDefragment(IP_t *ip, int *lenp)
+static inline struct ip_udp_hdr *NetDefragment(struct ip_udp_hdr *ip, int *lenp)
 {
        u16 ip_off = ntohs(ip->ip_off);
        if (!(ip_off & (IP_OFFS | IP_FLAGS_MFRAG)))
@@ -823,7 +822,8 @@ static inline IP_t *NetDefragment(IP_t *ip, int *lenp)
  *
  * @parma ip   IP packet containing the ICMP
  */
-static void receive_icmp(IP_t *ip, int len, IPaddr_t src_ip, Ethernet_t *et)
+static void receive_icmp(struct ip_udp_hdr *ip, int len,
+                       IPaddr_t src_ip, Ethernet_t *et)
 {
        ICMP_t *icmph = (ICMP_t *)&ip->udp_src;
 
@@ -852,10 +852,7 @@ void
 NetReceive(uchar *inpkt, int len)
 {
        Ethernet_t *et;
-       IP_t    *ip;
-#ifdef CONFIG_CMD_RARP
-       ARP_t   *arp;
-#endif
+       struct ip_udp_hdr *ip;
        IPaddr_t tmp;
        IPaddr_t src_ip;
        int     x;
@@ -903,11 +900,11 @@ NetReceive(uchar *inpkt, int len)
                 */
                x = ntohs(et->et_prot);
 
-               ip = (IP_t *)(inpkt + E802_HDR_SIZE);
+               ip = (struct ip_udp_hdr *)(inpkt + E802_HDR_SIZE);
                len -= E802_HDR_SIZE;
 
        } else if (x != PROT_VLAN) {    /* normal packet */
-               ip = (IP_t *)(inpkt + ETHER_HDR_SIZE);
+               ip = (struct ip_udp_hdr *)(inpkt + ETHER_HDR_SIZE);
                len -= ETHER_HDR_SIZE;
 
        } else {                        /* VLAN packet */
@@ -931,7 +928,7 @@ NetReceive(uchar *inpkt, int len)
                vlanid = cti & VLAN_IDMASK;
                x = ntohs(vet->vet_type);
 
-               ip = (IP_t *)(inpkt + VLAN_ETHER_HDR_SIZE);
+               ip = (struct ip_udp_hdr *)(inpkt + VLAN_ETHER_HDR_SIZE);
                len -= VLAN_ETHER_HDR_SIZE;
        }
 
@@ -960,34 +957,15 @@ NetReceive(uchar *inpkt, int len)
 
 #ifdef CONFIG_CMD_RARP
        case PROT_RARP:
-               debug("Got RARP\n");
-               arp = (ARP_t *)ip;
-               if (len < ARP_HDR_SIZE) {
-                       printf("bad length %d < %d\n", len, ARP_HDR_SIZE);
-                       return;
-               }
-
-               if ((ntohs(arp->ar_op) != RARPOP_REPLY) ||
-                       (ntohs(arp->ar_hrd) != ARP_ETHER)   ||
-                       (ntohs(arp->ar_pro) != PROT_IP)     ||
-                       (arp->ar_hln != 6) || (arp->ar_pln != 4)) {
-
-                       puts("invalid RARP header\n");
-               } else {
-                       NetCopyIP(&NetOurIP, &arp->ar_data[16]);
-                       if (NetServerIP == 0)
-                               NetCopyIP(&NetServerIP, &arp->ar_data[6]);
-                       memcpy(NetServerEther, &arp->ar_data[0], 6);
-
-                       (*packetHandler)(0, 0, 0, 0, 0);
-               }
+               rarp_receive(ip, len);
                break;
 #endif
        case PROT_IP:
                debug("Got IP\n");
                /* Before we start poking the header, make sure it is there */
-               if (len < IP_HDR_SIZE) {
-                       debug("len bad %d < %lu\n", len, (ulong)IP_HDR_SIZE);
+               if (len < IP_UDP_HDR_SIZE) {
+                       debug("len bad %d < %lu\n", len,
+                               (ulong)IP_UDP_HDR_SIZE);
                        return;
                }
                /* Check the packet length */
@@ -1005,7 +983,7 @@ NetReceive(uchar *inpkt, int len)
                if ((ip->ip_hl_v & 0x0f) > 0x05)
                        return;
                /* Check the Checksum of the header */
-               if (!NetCksumOk((uchar *)ip, IP_HDR_SIZE_NO_UDP / 2)) {
+               if (!NetCksumOk((uchar *)ip, IP_HDR_SIZE / 2)) {
                        puts("checksum bad\n");
                        return;
                }
@@ -1099,19 +1077,19 @@ NetReceive(uchar *inpkt, int len)
 
 
 #ifdef CONFIG_NETCONSOLE
-               nc_input_packet((uchar *)ip + IP_HDR_SIZE,
-                                               ntohs(ip->udp_dst),
-                                               ntohs(ip->udp_src),
-                                               ntohs(ip->udp_len) - 8);
+               nc_input_packet((uchar *)ip + IP_UDP_HDR_SIZE,
+                                       ntohs(ip->udp_dst),
+                                       ntohs(ip->udp_src),
+                                       ntohs(ip->udp_len) - UDP_HDR_SIZE);
 #endif
                /*
                 *      IP header OK.  Pass the packet to the current handler.
                 */
-               (*packetHandler)((uchar *)ip + IP_HDR_SIZE,
-                                               ntohs(ip->udp_dst),
-                                               src_ip,
-                                               ntohs(ip->udp_src),
-                                               ntohs(ip->udp_len) - 8);
+               (*packetHandler)((uchar *)ip + IP_UDP_HDR_SIZE,
+                                       ntohs(ip->udp_dst),
+                                       src_ip,
+                                       ntohs(ip->udp_src),
+                                       ntohs(ip->udp_len) - UDP_HDR_SIZE);
                break;
        }
 }
@@ -1262,10 +1240,9 @@ NetSetEther(uchar *xet, uchar * addr, uint prot)
        }
 }
 
-void
-NetSetIP(uchar *xip, IPaddr_t dest, int dport, int sport, int len)
+void NetSetIP(uchar *xip, IPaddr_t dest, int dport, int sport, int len)
 {
-       IP_t *ip = (IP_t *)xip;
+       struct ip_udp_hdr *ip = (struct ip_udp_hdr *)xip;
 
        /*
         *      If the data is an odd number of bytes, zero the
@@ -1273,7 +1250,7 @@ NetSetIP(uchar *xip, IPaddr_t dest, int dport, int sport, int len)
         *      will work.
         */
        if (len & 1)
-               xip[IP_HDR_SIZE + len] = 0;
+               xip[IP_UDP_HDR_SIZE + len] = 0;
 
        /*
         *      Construct an IP and UDP header.
@@ -1282,7 +1259,7 @@ NetSetIP(uchar *xip, IPaddr_t dest, int dport, int sport, int len)
        /* IP_HDR_SIZE / 4 (not including UDP) */
        ip->ip_hl_v  = 0x45;
        ip->ip_tos   = 0;
-       ip->ip_len   = htons(IP_HDR_SIZE + len);
+       ip->ip_len   = htons(IP_UDP_HDR_SIZE + len);
        ip->ip_id    = htons(NetIPID++);
        ip->ip_off   = htons(IP_FLAGS_DFRAG);   /* Don't fragment */
        ip->ip_ttl   = 255;
@@ -1294,9 +1271,9 @@ NetSetIP(uchar *xip, IPaddr_t dest, int dport, int sport, int len)
        NetCopyIP((void *)&ip->ip_dst, &dest);
        ip->udp_src  = htons(sport);
        ip->udp_dst  = htons(dport);
-       ip->udp_len  = htons(8 + len);
+       ip->udp_len  = htons(UDP_HDR_SIZE + len);
        ip->udp_xsum = 0;
-       ip->ip_sum   = ~NetCksum((uchar *)ip, IP_HDR_SIZE_NO_UDP / 2);
+       ip->ip_sum   = ~NetCksum((uchar *)ip, IP_HDR_SIZE / 2);
 }
 
 void copy_filename(char *dst, const char *src, int size)