OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [linux-2.4/] [net/] [802/] [fc.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1275 phoenix
/*
2
 * NET3:        Fibre Channel device handling subroutines
3
 *
4
 *              This program is free software; you can redistribute it and/or
5
 *              modify it under the terms of the GNU General Public License
6
 *              as published by the Free Software Foundation; either version
7
 *              2 of the License, or (at your option) any later version.
8
 *
9
 *              Vineet Abraham <vma@iol.unh.edu>
10
 *              v 1.0 03/22/99
11
 */
12
 
13
#include <linux/config.h>
14
#include <linux/module.h>
15
 
16
#include <asm/uaccess.h>
17
#include <asm/system.h>
18
#include <linux/types.h>
19
#include <linux/kernel.h>
20
#include <linux/sched.h>
21
#include <linux/string.h>
22
#include <linux/mm.h>
23
#include <linux/socket.h>
24
#include <linux/in.h>
25
#include <linux/inet.h>
26
#include <linux/netdevice.h>
27
#include <linux/fcdevice.h>
28
#include <linux/skbuff.h>
29
#include <linux/errno.h>
30
#include <linux/timer.h>
31
#include <linux/net.h>
32
#include <linux/proc_fs.h>
33
#include <linux/init.h>
34
#include <net/arp.h>
35
 
36
/*
37
 *      Put the headers on a Fibre Channel packet.
38
 */
39
 
40
int fc_header(struct sk_buff *skb, struct net_device *dev, unsigned short type,
41
              void *daddr, void *saddr, unsigned len)
42
{
43
        struct fch_hdr *fch;
44
        int hdr_len;
45
 
46
        /*
47
         * Add the 802.2 SNAP header if IP as the IPv4 code calls
48
         * dev->hard_header directly.
49
         */
50
        if (type == ETH_P_IP || type == ETH_P_ARP)
51
        {
52
                struct fcllc *fcllc=(struct fcllc *)(fch+1);
53
 
54
                hdr_len = sizeof(struct fch_hdr) + sizeof(struct fcllc);
55
                fch = (struct fch_hdr *)skb_push(skb, hdr_len);
56
                fcllc = (struct fcllc *)(fch+1);
57
                fcllc->dsap = fcllc->ssap = EXTENDED_SAP;
58
                fcllc->llc = UI_CMD;
59
                fcllc->protid[0] = fcllc->protid[1] = fcllc->protid[2] = 0x00;
60
                fcllc->ethertype = htons(type);
61
        }
62
        else
63
        {
64
                hdr_len = sizeof(struct fch_hdr);
65
                fch = (struct fch_hdr *)skb_push(skb, hdr_len);
66
        }
67
 
68
        if(saddr)
69
                memcpy(fch->saddr,saddr,dev->addr_len);
70
        else
71
                memcpy(fch->saddr,dev->dev_addr,dev->addr_len);
72
 
73
        if(daddr)
74
        {
75
                memcpy(fch->daddr,daddr,dev->addr_len);
76
                return(hdr_len);
77
        }
78
        return -hdr_len;
79
}
80
 
81
/*
82
 *      A neighbour discovery of some species (eg arp) has completed. We
83
 *      can now send the packet.
84
 */
85
 
86
int fc_rebuild_header(struct sk_buff *skb)
87
{
88
        struct fch_hdr *fch=(struct fch_hdr *)skb->data;
89
        struct fcllc *fcllc=(struct fcllc *)(skb->data+sizeof(struct fch_hdr));
90
        if(fcllc->ethertype != htons(ETH_P_IP)) {
91
                printk("fc_rebuild_header: Don't know how to resolve type %04X addresses ?\n",(unsigned int)htons(fcllc->ethertype));
92
                return 0;
93
        }
94
#ifdef CONFIG_INET
95
        return arp_find(fch->daddr, skb);
96
#else
97
        return 0;
98
#endif
99
}
100
 
101
EXPORT_SYMBOL(fc_type_trans);
102
 
103
unsigned short
104
fc_type_trans(struct sk_buff *skb, struct net_device *dev)
105
{
106
        struct fch_hdr *fch = (struct fch_hdr *)skb->data;
107
        struct fcllc *fcllc;
108
 
109
        skb->mac.raw = skb->data;
110
        fcllc = (struct fcllc *)(skb->data + sizeof (struct fch_hdr) + 2);
111
        skb_pull(skb, sizeof (struct fch_hdr) + 2);
112
 
113
        if (*fch->daddr & 1) {
114
                if (!memcmp(fch->daddr, dev->broadcast, FC_ALEN))
115
                        skb->pkt_type = PACKET_BROADCAST;
116
                else
117
                        skb->pkt_type = PACKET_MULTICAST;
118
        } else if (dev->flags & IFF_PROMISC) {
119
                if (memcmp(fch->daddr, dev->dev_addr, FC_ALEN))
120
                        skb->pkt_type = PACKET_OTHERHOST;
121
        }
122
 
123
        /*
124
         * Strip the SNAP header from ARP packets since we don't pass
125
         * them through to the 802.2/SNAP layers.
126
         */
127
        if (fcllc->dsap == EXTENDED_SAP &&
128
            (fcllc->ethertype == ntohs(ETH_P_IP) ||
129
             fcllc->ethertype == ntohs(ETH_P_ARP))) {
130
                skb_pull(skb, sizeof (struct fcllc));
131
                return fcllc->ethertype;
132
        }
133
 
134
        return ntohs(ETH_P_802_2);
135
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.