This source file includes following definitions.
- ip_alias_init_1
- ip_alias_done_1
- ip_alias_print_1
- ip_alias_dev_select
- ip_alias_init
- ip_alias_done
- init_module
- cleanup_module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 #include <linux/module.h>
20
21 #include <linux/types.h>
22 #include <linux/errno.h>
23 #include <linux/netdevice.h>
24 #include <linux/if.h>
25 #include <linux/inet.h>
26 #include <linux/in.h>
27 #include <linux/ip.h>
28 #include <linux/route.h>
29 #include <net/route.h>
30
31 #ifdef ALIAS_USER_LAND_DEBUG
32 #include "net_alias.h"
33 #include "ip_alias.h"
34 #include "user_stubs.h"
35 #endif
36
37 #include <linux/net_alias.h>
38 #include <net/ip_alias.h>
39
40
41
42
43
44 static int ip_alias_init_1(struct net_alias_type *this, struct net_alias *alias, struct sockaddr *sa)
45 {
46 #ifdef ALIAS_USER_LAND_DEBUG
47 printk("alias_init(%s) called.\n", alias->name);
48 #endif
49 MOD_INC_USE_COUNT;
50 return 0;
51 }
52
53
54
55
56
57 static int ip_alias_done_1(struct net_alias_type *this, struct net_alias *alias)
58 {
59 #ifdef ALIAS_USER_LAND_DEBUG
60 printk("alias_done(%s) called.\n", alias->name);
61 #endif
62 MOD_DEC_USE_COUNT;
63 return 0;
64 }
65
66
67
68
69
70 int ip_alias_print_1(struct net_alias_type *this, struct net_alias *alias, char *buf, int len)
71 {
72 char *p;
73
74 p = (char *) &alias->dev.pa_addr;
75 return sprintf(buf, "%d.%d.%d.%d",
76 (p[0] & 255), (p[1] & 255), (p[2] & 255), (p[3] & 255));
77 }
78
79 struct device *ip_alias_dev_select(struct net_alias_type *this, struct device *main_dev, struct sockaddr *sa)
80 {
81 __u32 addr;
82 struct rtable *rt;
83 struct device *dev=NULL;
84
85
86
87
88
89 if (main_dev == NULL)
90 return NULL;
91
92
93
94
95
96 addr = (sa)? (*(struct sockaddr_in *)sa).sin_addr.s_addr : 0;
97 if (addr == 0)
98 return NULL;
99
100
101
102
103
104
105 rt = ip_rt_route(addr, 0);
106 if(rt)
107 {
108 dev=rt->rt_dev;
109 ip_rt_put(rt);
110 }
111 return dev;
112 }
113
114
115
116
117
118 struct net_alias_type ip_alias_type =
119 {
120 AF_INET,
121 0,
122 "ip",
123 NULL,
124 NULL,
125 ip_alias_dev_select,
126 ip_alias_init_1,
127 ip_alias_done_1,
128 ip_alias_print_1,
129 NULL
130 };
131
132
133
134
135
136 int ip_alias_init(void)
137 {
138 return register_net_alias_type(&ip_alias_type, AF_INET);
139 }
140
141
142
143
144
145 int ip_alias_done(void)
146 {
147 return unregister_net_alias_type(&ip_alias_type);
148 }
149
150 #ifdef MODULE
151
152 int init_module(void)
153 {
154 if (ip_alias_init() != 0)
155 return -EIO;
156 return 0;
157 }
158
159 void cleanup_module(void)
160 {
161 if (ip_alias_done() != 0)
162 printk("ip_alias: can't remove module");
163 }
164
165 #endif