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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rc203soc/] [sw/] [uClinux/] [net/] [ipv4/] [ip_alias.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1629 jcastillo
/*
2
 *              IP_ALIAS (AF_INET) aliasing module.
3
 *
4
 *
5
 * Version:     @(#)ip_alias.c  0.50   6/14/97
6
 *
7
 * Author:      Juan Jose Ciarlante, <jjciarla@raiz.uncu.edu.ar>
8
 *
9
 * Fixes:
10
 *      JJC     :       ip_alias_dev_select method.
11
 *      JJC     :       use ip_rt_dev instead of ip_rt_route
12
 *      JJC     :       new no_sel semantics
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
 */
20
 
21
#include <linux/module.h>
22
 
23
#include <linux/types.h>
24
#include <linux/errno.h>
25
#include <linux/netdevice.h>
26
#include <linux/if.h>
27
#include <linux/inet.h>
28
#include <linux/in.h>
29
#include <linux/ip.h>
30
#include <linux/route.h>
31
#include <net/route.h>
32
 
33
#ifdef ALIAS_USER_LAND_DEBUG
34
#include "net_alias.h"
35
#include "ip_alias.h"
36
#include "user_stubs.h"
37
#endif
38
 
39
#include <linux/net_alias.h>
40
#include <net/ip_alias.h>
41
 
42
/*
43
 *      AF_INET alias init
44
 */
45
 
46
static int ip_alias_init_1(struct net_alias_type *this, struct net_alias *alias, struct sockaddr *sa)
47
{
48
#ifdef ALIAS_USER_LAND_DEBUG
49
        printk("alias_init(%s) called.\n", alias->name);
50
#endif
51
        MOD_INC_USE_COUNT;
52
        return 0;
53
}
54
 
55
/*
56
 *      AF_INET alias done
57
 */
58
 
59
static int ip_alias_done_1(struct net_alias_type *this, struct net_alias *alias)
60
{
61
#ifdef ALIAS_USER_LAND_DEBUG
62
        printk("alias_done(%s) called.\n", alias->name);
63
#endif
64
        MOD_DEC_USE_COUNT;
65
        return 0;
66
}
67
 
68
/*
69
 *      Print alias address info
70
 */
71
 
72
int ip_alias_print_1(struct net_alias_type *this, struct net_alias *alias, char *buf, int len)
73
{
74
        char *p;
75
 
76
        p = (char *) &alias->dev.pa_addr;
77
        return sprintf(buf, "%d.%d.%d.%d",
78
                (p[0] & 255), (p[1] & 255), (p[2] & 255), (p[3] & 255));
79
}
80
 
81
/*
82
 *      Called by net_alias module when no local alias address has been hit,
83
 *      to find out if an alias is a better candidate for handling given addr
84
 */
85
struct device *ip_alias_dev_select(struct net_alias_type *this, struct device *main_dev, struct sockaddr *sa)
86
{
87
        __u32 addr;
88
 
89
        /*
90
         *      Defensive...
91
         */
92
 
93
        if (main_dev == NULL)
94
                return NULL;
95
 
96
        /*
97
         *      Get u32 address.
98
         */
99
 
100
        addr =  (sa)? (*(struct sockaddr_in *)sa).sin_addr.s_addr : 0;
101
        if (addr == 0)
102
                return NULL;
103
 
104
        /*
105
         *      Find 'closest' device to address given. any other suggestions? ...
106
         *      net_alias module will check if returned device is main_dev's alias
107
         */
108
 
109
        /*
110
         *      Fixed arping caused by incorrectly using ip_rt_route(),
111
         *      ip_rt_dev() just returns routing device without hh generation.
112
         */
113
 
114
        return ip_rt_dev(addr);
115
}
116
 
117
/*
118
 * net_alias AF_INET type defn.
119
 */
120
 
121
struct net_alias_type ip_alias_type =
122
{
123
        AF_INET,                /* type */
124
        0,                       /* n_attach */
125
        "ip",                   /* name */
126
        NULL,                   /* get_addr32() */
127
        NULL,                   /* dev_addr_chk() */
128
        ip_alias_dev_select,    /* dev_select() */
129
        ip_alias_init_1,        /* alias_init_1() */
130
        ip_alias_done_1,        /* alias_done_1() */
131
        ip_alias_print_1,       /* alias_print_1() */
132
        NULL                    /* next */
133
};
134
 
135
/*
136
 * ip_alias module initialization
137
 */
138
 
139
int ip_alias_init(void)
140
{
141
        return register_net_alias_type(&ip_alias_type, AF_INET);
142
}
143
 
144
/*
145
 * ip_alias module done
146
 */
147
 
148
int ip_alias_done(void)
149
{
150
        return unregister_net_alias_type(&ip_alias_type);
151
}
152
 
153
#ifdef MODULE
154
 
155
/*
156
 *      If no_sel is set, alias association (device selection) with
157
 *      foreign addresses will be disabled.
158
 *      You will get:
159
 *      - faster operation by avoiding completely routing lookups
160
 *      You will loose:
161
 *      - inter-alias routing
162
 *      - proxyarp over aliases
163
 */
164
 
165
int no_sel = 0;
166
 
167
int init_module(void)
168
{
169
        if (no_sel)
170
                ip_alias_type.dev_select = NULL;
171
 
172
        if (ip_alias_init() != 0)
173
                return -EIO;
174
        return 0;
175
}
176
 
177
void cleanup_module(void)
178
{
179
        if (ip_alias_done() != 0)
180
                printk(KERN_INFO "ip_alias: can't remove module");
181
}
182
 
183
#endif /* MODULE */

powered by: WebSVN 2.1.0

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