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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [uclinux/] [uC-libc/] [include/] [linux/] [net_alias.h] - Blame information for rev 199

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 199 simons
/*
2
 *              NET_ALIAS network device aliasing definitions.
3
 *
4
 *
5
 * Version:     @(#)net_alias.h 0.50   4/20/97
6
 *
7
 * Author:      Juan Jose Ciarlante, <jjciarla@raiz.uncu.edu.ar>
8
 *
9
 *
10
 *      This program is free software; you can redistribute it and/or
11
 *      modify it under the terms of the GNU General Public License
12
 *      as published by the Free Software Foundation; either version
13
 *      2 of the License, or (at your option) any later version.
14
 *
15
 * Fixes:
16
 *      Juan Jose Ciarlante     :       Added tx/rx stats for aliases.
17
 *      Juan Jose Ciarlante     :       hash_tab size now in net_alias.c
18
 *      Juan Jose Ciarlante     :       added sysctl interface
19
 */
20
 
21
#ifndef _NET_ALIAS_H
22
#define _NET_ALIAS_H
23
 
24
#include <linux/types.h>
25
#include <linux/if.h>
26
#include <linux/netdevice.h>
27
 
28
struct net_alias;
29
struct net_alias_info;
30
struct net_alias_type;
31
 
32
 
33
/*
34
 * main alias structure
35
 * note that *defines* dev & devname
36
 */
37
 
38
struct net_alias
39
{
40
  struct device dev;            /* alias device defn*/
41
  char name[IFNAMSIZ];          /* device name defn */
42
  unsigned hash;                /* my hash value: for quick rehash */
43
  unsigned slot;                /* slot number */
44
  void *data;                   /* private data */
45
  struct device *main_dev;      /* pointer to main device */
46
  struct net_alias_type *nat;   /* alias type object bound */
47
  struct net_alias *next;       /* next alias (hashed linked list) */
48
  unsigned long rx_lookups;     /* 'fake' rx pkts */
49
  unsigned long tx_lookups;     /* 'fake' tx pkts */
50
};
51
 
52
 
53
/*
54
 *  alias structure pointed by main device
55
 *  it holds main device's alias hash table
56
 */
57
 
58
struct net_alias_info
59
{
60
  int n_aliases;                /* num aliases */
61
  int truesize;                 /* actual malloc size for struct + hashtab */
62
  struct device *taildev;       /* my last (alias) device */
63
  int max_aliases;              /* max aliases allowed for main device */
64
  unsigned hash_tab_size;       /* hash_tab size in elements */
65
  struct net_alias *hash_tab[0]; /* hashed alias table */
66
};
67
 
68
/*
69
 * net_alias_type class
70
 * declares a generic (AF_ independent) structure that will
71
 * manage generic to family-specific behavior.
72
 */
73
 
74
struct net_alias_type
75
{
76
  int type;                     /* aliasing type: address family */
77
  int n_attach;                 /* number of aliases attached */
78
  char name[16];                /* af_name */
79
  __u32 (*get_addr32)           /* get __u32 addr 'representation'*/
80
    (struct net_alias_type *this, struct sockaddr*);
81
  int (*dev_addr_chk)           /* address checking func: */
82
    (struct net_alias_type *this, struct device *, struct sockaddr *);
83
  struct device * (*dev_select) /* closest alias selector*/
84
    (struct net_alias_type *this, struct device *, struct sockaddr *sa);
85
  int (*alias_init_1)           /* called after alias creation: */
86
    (struct net_alias_type *this,struct net_alias *alias, struct sockaddr *sa);
87
  int (*alias_done_1)           /* called before alias deletion */
88
    (struct net_alias_type *this, struct net_alias *alias);
89
  int (*alias_print_1)
90
    (struct net_alias_type *this, struct net_alias *alias, char *buf, int len);
91
  struct net_alias_type *next;  /* link */
92
};
93
 
94
 
95
/*
96
 * is dev an alias?
97
 */
98
 
99
static __inline__ int
100
net_alias_is(struct device *dev)
101
{
102
  return (dev->my_alias != NULL);
103
}
104
 
105
 
106
/*
107
 * does dev have aliases?
108
 */
109
 
110
static __inline__ int
111
net_alias_has(struct device *dev)
112
{
113
  return (dev->alias_info != NULL);
114
}
115
 
116
/*
117
 *      Initialise net_alias module
118
 */
119
extern void net_alias_init(void);
120
 
121
/*
122
 *      dev_get() with added aliasing magic
123
 */
124
extern struct device * net_alias_dev_get(char *dev_name, int aliasing_ok, int *err, struct sockaddr *sa, void *data);
125
extern int net_alias_dev_rehash(struct device *dev, struct sockaddr *sa);
126
 
127
/*
128
 *      PROC_FS entries
129
 */
130
extern int net_alias_getinfo(char *buf, char **, off_t , int , int );
131
extern int net_alias_types_getinfo(char *buf, char **, off_t , int , int );
132
 
133
/*
134
 *      net_alias_type (address family) registration
135
 */
136
extern int register_net_alias_type(struct net_alias_type *nat, int type);
137
extern int unregister_net_alias_type(struct net_alias_type *nat);
138
 
139
/*
140
 *      get alias device _with_ specified address
141
 */
142
extern struct device * net_alias_dev_chk(struct device *main_dev, struct sockaddr *sa, int flags_on, int flags_off);
143
extern struct device * net_alias_dev_chk32(struct device *main_dev, int family, __u32 addr32, int flags_on, int flags_off);
144
 
145
/*
146
 *      get 'closest' device to specified address (returns main_dev if
147
 *      nothing better)
148
 *      if succesfull, also increment rx stats.
149
 */
150
extern struct device * net_alias_dev_rx(struct device *main_dev, struct sockaddr *sa_src, struct sockaddr *sa_dst);
151
extern struct device * net_alias_dev_rx32(struct device *main_dev, int family, __u32 src, __u32 dst);
152
 
153
 
154
/*
155
 * returns MY 'true' main device
156
 * intended for alias devices
157
 */
158
 
159
static __inline__ struct device *net_alias_main_dev(struct device *dev)
160
{
161
  return (net_alias_is(dev))? dev->my_alias->main_dev : dev;
162
}
163
 
164
 
165
/*
166
 * returns NEXT 'true' device
167
 * intended for true devices
168
 */
169
 
170
static __inline__ struct device *
171
net_alias_nextdev(struct device *dev)
172
{
173
  return (dev->alias_info)? dev->alias_info->taildev->next : dev->next;
174
}
175
 
176
 
177
/*
178
 * sets NEXT 'true' device
179
 * intended for main devices (treat main device as block: dev+aliases).
180
 */
181
 
182
static __inline__ struct device *
183
net_alias_nextdev_set(struct device *dev, struct device *nextdev)
184
{
185
  struct device *pdev = dev;
186
  if (net_alias_has(dev))
187
  {
188
    pdev = dev->alias_info->taildev; /* point to last dev alias */
189
  }
190
  pdev->next = nextdev;
191
  return nextdev;
192
}
193
 
194
/*
195
 *      lookup counters (used for alias devices stats)
196
 */
197
static __inline__ void net_alias_inc_rx(struct net_alias *alias)
198
{
199
        if (alias != NULL) alias->rx_lookups++;
200
}
201
static __inline__ void net_alias_inc_tx(struct net_alias *alias)
202
{
203
        if (alias != NULL) alias->tx_lookups++;
204
}
205
 
206
/*
207
 *      To be called when passing down a pkt, to _switch_ from alias device
208
 *      to actual device, also incr. alias tx counter.
209
 */
210
static __inline__ struct device *net_alias_dev_tx(struct device *dev)
211
{
212
        struct net_alias *alias = dev->my_alias;
213
        if (alias) {
214
                net_alias_inc_tx(alias);
215
                return alias->main_dev;
216
        }
217
        return dev;
218
}
219
 
220
#endif  /* _NET_ALIAS_H */

powered by: WebSVN 2.1.0

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