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