(void) eth_send(pkt, len);
}
-int
-NetSendUDPPacket(uchar *ether, IPaddr_t dest, int dport, int sport, int len)
+int NetSendUDPPacket(uchar *ether, IPaddr_t dest, int dport, int sport,
+ int payload_len)
{
uchar *pkt;
pkt = NetArpWaitTxPacket;
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);
+ NetSetIP(pkt, dest, dport, sport, payload_len);
+ memcpy(pkt + IP_UDP_HDR_SIZE, (uchar *)NetTxPacket +
+ (pkt - (uchar *)NetArpWaitTxPacket) +
+ IP_UDP_HDR_SIZE, payload_len);
/* size of the waiting packet */
NetArpWaitTxPacketSize = (pkt - NetArpWaitTxPacket) +
- IP_HDR_SIZE + len;
+ IP_UDP_HDR_SIZE + payload_len;
/* and do the ARP request */
NetArpWaitTry = 1;
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);
+ NetSetIP(pkt, dest, dport, sport, payload_len);
+ eth_send(NetTxPacket, (pkt - NetTxPacket) + IP_UDP_HDR_SIZE +
+ payload_len);
return 0; /* transmitted */
}
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.
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;
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);
}
/*
}
/* 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)))
#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)))
*
* @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, struct ethernet_hdr *et)
{
- ICMP_t *icmph = (ICMP_t *)&ip->udp_src;
+ struct icmp_hdr *icmph = (struct icmp_hdr *)&ip->udp_src;
switch (icmph->type) {
case ICMP_REDIRECT:
void
NetReceive(uchar *inpkt, int len)
{
- Ethernet_t *et;
- IP_t *ip;
- IPaddr_t tmp;
+ struct ethernet_hdr *et;
+ struct ip_udp_hdr *ip;
+ IPaddr_t dst_ip;
IPaddr_t src_ip;
- int x;
+ int eth_proto;
#if defined(CONFIG_CMD_CDP)
int iscdp;
#endif
NetRxPacket = inpkt;
NetRxPacketLen = len;
- et = (Ethernet_t *)inpkt;
+ et = (struct ethernet_hdr *)inpkt;
/* too small packet? */
if (len < ETHER_HDR_SIZE)
if (mynvlanid == (ushort)-1)
mynvlanid = VLAN_NONE;
- x = ntohs(et->et_protlen);
+ eth_proto = ntohs(et->et_protlen);
debug("packet received\n");
- if (x < 1514) {
+ if (eth_proto < 1514) {
+ struct e802_hdr *et802 = (struct e802_hdr *)et;
/*
- * Got a 802 packet. Check the other protocol field.
+ * Got a 802.2 packet. Check the other protocol field.
+ * XXX VLAN over 802.2+SNAP not implemented!
*/
- x = ntohs(et->et_prot);
+ eth_proto = ntohs(et802->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);
+ } else if (eth_proto != PROT_VLAN) { /* normal packet */
+ ip = (struct ip_udp_hdr *)(inpkt + ETHER_HDR_SIZE);
len -= ETHER_HDR_SIZE;
} else { /* VLAN packet */
- VLAN_Ethernet_t *vet = (VLAN_Ethernet_t *)et;
+ struct vlan_ethernet_hdr *vet =
+ (struct vlan_ethernet_hdr *)et;
debug("VLAN packet received\n");
cti = ntohs(vet->vet_tag);
vlanid = cti & VLAN_IDMASK;
- x = ntohs(vet->vet_type);
+ eth_proto = 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;
}
- debug("Receive from protocol 0x%x\n", x);
+ debug("Receive from protocol 0x%x\n", eth_proto);
#if defined(CONFIG_CMD_CDP)
if (iscdp) {
return;
}
- switch (x) {
+ switch (eth_proto) {
case PROT_ARP:
ArpReceive(et, ip, len);
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 */
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;
}
/* If it is not for us, ignore it */
- tmp = NetReadIP(&ip->ip_dst);
- if (NetOurIP && tmp != NetOurIP && tmp != 0xFFFFFFFF) {
+ dst_ip = NetReadIP(&ip->ip_dst);
+ if (NetOurIP && dst_ip != NetOurIP && dst_ip != 0xFFFFFFFF) {
#ifdef CONFIG_MCAST_TFTP
- if (Mcast_addr != tmp)
+ if (Mcast_addr != dst_ip)
#endif
return;
}
#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;
}
}
int
NetSetEther(uchar *xet, uchar * addr, uint prot)
{
- Ethernet_t *et = (Ethernet_t *)xet;
+ struct ethernet_hdr *et = (struct ethernet_hdr *)xet;
ushort myvlanid;
myvlanid = ntohs(NetOurVLAN);
et->et_protlen = htons(prot);
return ETHER_HDR_SIZE;
} else {
- VLAN_Ethernet_t *vet = (VLAN_Ethernet_t *)xet;
+ struct vlan_ethernet_hdr *vet =
+ (struct vlan_ethernet_hdr *)xet;
vet->vet_vlan_type = htons(PROT_VLAN);
vet->vet_tag = htons((0 << 5) | (myvlanid & VLAN_IDMASK));
}
}
-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
* will work.
*/
if (len & 1)
- xip[IP_HDR_SIZE + len] = 0;
+ xip[IP_UDP_HDR_SIZE + len] = 0;
/*
* Construct an IP and UDP header.
/* 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;
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)