root/net/inet/eth.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. eth_print
  2. eth_setup
  3. eth_dump
  4. eth_header
  5. eth_rebuild_header
  6. eth_add_arp
  7. eth_type_trans

   1 /*
   2  * INET         An implementation of the TCP/IP protocol suite for the LINUX
   3  *              operating system.  INET is implemented using the  BSD Socket
   4  *              interface as the means of communication with the user level.
   5  *
   6  *              Ethernet-type device handling.
   7  *
   8  * Version:     @(#)eth.c       1.0.7   05/25/93
   9  *
  10  * Authors:     Ross Biro, <bir7@leland.Stanford.Edu>
  11  *              Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
  12  *              Mark Evans, <evansmp@uhura.aston.ac.uk>
  13  *
  14  *              This program is free software; you can redistribute it and/or
  15  *              modify it under the terms of the GNU General Public License
  16  *              as published by the Free Software Foundation; either version
  17  *              2 of the License, or (at your option) any later version.
  18  */
  19 #include <asm/segment.h>
  20 #include <asm/system.h>
  21 #include <linux/types.h>
  22 #include <linux/kernel.h>
  23 #include <linux/sched.h>
  24 #include <linux/string.h>
  25 #include <linux/mm.h>
  26 #include <linux/socket.h>
  27 #include <linux/in.h>
  28 #include "inet.h"
  29 #include "dev.h"
  30 #include "eth.h"
  31 #include "timer.h"
  32 #include "ip.h"
  33 #include "route.h"
  34 #include "protocol.h"
  35 #include "tcp.h"
  36 #include "skbuff.h"
  37 #include "sock.h"
  38 #include <linux/errno.h>
  39 #include "arp.h"
  40 
  41 
  42 /* Display an Ethernet address in readable format. */
  43 char *eth_print(unsigned char *ptr)
     /* [previous][next][first][last][top][bottom][index][help] */
  44 {
  45   static char buff[64];
  46 
  47   if (ptr == NULL) return("[NONE]");
  48   sprintf(buff, "%02X:%02X:%02X:%02X:%02X:%02X",
  49         (ptr[0] & 255), (ptr[1] & 255), (ptr[2] & 255),
  50         (ptr[3] & 255), (ptr[4] & 255), (ptr[5] & 255)
  51   );
  52   return(buff);
  53 }
  54 
  55 void eth_setup(char *str, int *ints)
     /* [previous][next][first][last][top][bottom][index][help] */
  56 {
  57         struct device *d = dev_base;
  58 
  59         if (!str || !*str)
  60                 return;
  61         while (d) {
  62                 if (!strcmp(str,d->name)) {
  63                         if (ints[0] > 0)
  64                                 d->irq=ints[1];
  65                         if (ints[0] > 1)
  66                                 d->base_addr=ints[2];
  67                         if (ints[0] > 2)
  68                                 d->mem_start=ints[3];
  69                         if (ints[0] > 3)
  70                                 d->mem_end=ints[4];
  71                         break;
  72                 }
  73                 d=d->next;
  74         }
  75 }
  76 
  77 /* Display the contents of the Ethernet MAC header. */
  78 void
  79 eth_dump(struct ethhdr *eth)
     /* [previous][next][first][last][top][bottom][index][help] */
  80 {
  81   if (inet_debug != DBG_ETH) return;
  82 
  83   printk("eth: SRC = %s ", eth_print(eth->h_source));
  84   printk("DST = %s ", eth_print(eth->h_dest));
  85   printk("TYPE = %04X\n", ntohs(eth->h_proto));
  86 }
  87 
  88 
  89 /* Create the Ethernet MAC header. */
  90 int
  91 eth_header(unsigned char *buff, struct device *dev, unsigned short type,
     /* [previous][next][first][last][top][bottom][index][help] */
  92            unsigned long daddr, unsigned long saddr, unsigned len)
  93 {
  94   struct ethhdr *eth;
  95 
  96   DPRINTF((DBG_DEV, "ETH: header(%s, ", in_ntoa(saddr)));
  97   DPRINTF((DBG_DEV, "%s, 0x%X)\n", in_ntoa(daddr), type));
  98 
  99   /* Fill in the basic Ethernet MAC header. */
 100   eth = (struct ethhdr *) buff;
 101   eth->h_proto = ntohs(type);
 102   memcpy(eth->h_source, dev->dev_addr, dev->addr_len);
 103 
 104   /* We don't ARP for the LOOPBACK device... */
 105   if (dev->flags & IFF_LOOPBACK) {
 106         DPRINTF((DBG_DEV, "ETH: No header for loopback\n"));
 107         memset(eth->h_dest, 0, dev->addr_len);
 108         return(dev->hard_header_len);
 109   }
 110 
 111   /* Check if we can use the MAC BROADCAST address. */
 112   if (chk_addr(daddr) == IS_BROADCAST) {
 113         DPRINTF((DBG_DEV, "ETH: Using MAC Broadcast\n"));
 114         memcpy(eth->h_dest, dev->broadcast, dev->addr_len);
 115         return(dev->hard_header_len);
 116   }
 117 
 118   /* No. Ask ARP to resolve the Ethernet address. */
 119   if (arp_find(eth->h_dest, daddr, dev, saddr)) {
 120         return(-dev->hard_header_len);
 121   } else return(dev->hard_header_len);
 122 }
 123 
 124 
 125 /* Rebuild the Ethernet MAC header. */
 126 int
 127 eth_rebuild_header(void *buff, struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 128 {
 129   struct ethhdr *eth;
 130   unsigned long src, dst;
 131 
 132   DPRINTF((DBG_DEV, "ETH: Using MAC Broadcast\n"));
 133   eth = (struct ethhdr *) buff;
 134   src = *(unsigned long *) eth->h_source;
 135   dst = *(unsigned long *) eth->h_dest;
 136   DPRINTF((DBG_DEV, "ETH: RebuildHeader: SRC=%s ", in_ntoa(src)));
 137   DPRINTF((DBG_DEV, "DST=%s\n", in_ntoa(dst)));
 138   if (arp_find(eth->h_dest, dst, dev, src)) return(1);
 139   memcpy(eth->h_source, dev->dev_addr, dev->addr_len);
 140   return(0);
 141 }
 142 
 143 
 144 /* Add an ARP entry for a host on this interface. */
 145 void
 146 eth_add_arp(unsigned long addr, struct sk_buff *skb, struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 147 {
 148   struct ethhdr *eth;
 149 
 150   eth = (struct ethhdr *) (skb + 1);
 151   arp_add(addr, eth->h_source, dev);
 152 }
 153 
 154 
 155 /* Determine the packet's protocol ID. */
 156 unsigned short
 157 eth_type_trans(struct sk_buff *skb, struct device *dev)
     /* [previous][next][first][last][top][bottom][index][help] */
 158 {
 159   struct ethhdr *eth;
 160 
 161   eth = (struct ethhdr *) (skb + 1);
 162   return(eth->h_proto);
 163 }

/* [previous][next][first][last][top][bottom][index][help] */