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 static int
44 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 static int
57 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
71 ip_alias_print_1(struct net_alias_type *this, struct net_alias *alias, char *buf, int len)
72 {
73 char *p;
74
75 p = (char *) &alias->dev.pa_addr;
76 return sprintf(buf, "%d.%d.%d.%d",
77 (p[0] & 255), (p[1] & 255), (p[2] & 255), (p[3] & 255));
78 }
79
80 struct device *
81 ip_alias_dev_select(struct net_alias_type *this, struct device *main_dev, struct sockaddr *sa)
82 {
83 __u32 addr;
84 struct rtable *rt;
85
86
87
88
89
90 if (main_dev == NULL) return NULL;
91
92
93
94
95
96 addr = (sa)? (*(struct sockaddr_in *)sa).sin_addr.s_addr : 0;
97
98 if (addr == 0) return NULL;
99
100
101
102
103
104
105 rt = ip_rt_route(addr, 0);
106
107 return (rt)? rt->rt_dev : NULL;
108
109 }
110
111
112
113
114
115 struct net_alias_type ip_alias_type =
116 {
117 AF_INET,
118 0,
119 "ip",
120 NULL,
121 NULL,
122 ip_alias_dev_select,
123 ip_alias_init_1,
124 ip_alias_done_1,
125 ip_alias_print_1,
126 NULL
127 };
128
129
130
131
132
133 int ip_alias_init(void)
134 {
135 return register_net_alias_type(&ip_alias_type, AF_INET);
136 }
137
138
139
140
141
142 int ip_alias_done(void)
143 {
144 return unregister_net_alias_type(&ip_alias_type);
145 }
146
147 #ifdef MODULE
148
149 int init_module(void)
150 {
151 if (ip_alias_init() != 0)
152 return -EIO;
153 return 0;
154 }
155
156 void cleanup_module(void)
157 {
158 if (ip_alias_done() != 0)
159 printk("ip_alias: can't remove module");
160 }
161
162 #endif