root/net/ipv4/ip_alias.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. ip_alias_init_1
  2. ip_alias_done_1
  3. ip_alias_print_1
  4. ip_alias_dev_select
  5. ip_alias_init
  6. ip_alias_done
  7. init_module
  8. cleanup_module

   1 /*
   2  *              IP_ALIAS (AF_INET) aliasing module.
   3  *
   4  *
   5  * Version:     @(#)ip_alias.c  0.43   12/20/95
   6  *
   7  * Author:      Juan Jose Ciarlante, <jjciarla@raiz.uncu.edu.ar>
   8  *
   9  * Fixes:
  10  *      JJC     :       ip_alias_dev_select method.
  11  *
  12  *      This program is free software; you can redistribute it and/or
  13  *      modify it under the terms of the GNU General Public License
  14  *      as published by the Free Software Foundation; either version
  15  *      2 of the License, or (at your option) any later version.
  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  * AF_INET alias init
  42  */
  43 static int 
  44 ip_alias_init_1(struct net_alias_type *this, struct net_alias *alias, struct sockaddr *sa)
     /* [previous][next][first][last][top][bottom][index][help] */
  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  * AF_INET alias done
  55  */
  56 static int
  57 ip_alias_done_1(struct net_alias_type *this, struct net_alias *alias)
     /* [previous][next][first][last][top][bottom][index][help] */
  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  * print alias address info
  68  */
  69 
  70 int
  71 ip_alias_print_1(struct net_alias_type *this, struct net_alias *alias, char *buf, int len)
     /* [previous][next][first][last][top][bottom][index][help] */
  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)
     /* [previous][next][first][last][top][bottom][index][help] */
  82 {
  83   __u32 addr;
  84   struct rtable *rt;
  85   
  86   /*
  87    * defensive...
  88    */
  89   
  90   if (main_dev == NULL) return NULL;
  91 
  92   /*
  93    * get u32 address. 
  94    */
  95 
  96   addr =  (sa)? (*(struct sockaddr_in *)sa).sin_addr.s_addr : 0;
  97 
  98   if (addr == 0) return NULL;
  99 
 100   /*
 101    * find 'closest' device to address given. any other suggestions? ...
 102    * net_alias module will check if returned device is main_dev's alias
 103    */
 104 
 105   rt = ip_rt_route(addr, 0);
 106 
 107   return (rt)? rt->rt_dev : NULL;
 108 
 109 }
 110 
 111 /*
 112  * net_alias AF_INET type defn.
 113  */
 114 
 115 struct net_alias_type ip_alias_type =
 116 {
 117   AF_INET,                      /* type */
 118   0,                            /* n_attach */
 119   "ip",                         /* name */
 120   NULL,                         /* get_addr32() */
 121   NULL,                         /* dev_addr_chk() */
 122   ip_alias_dev_select,          /* dev_select() */
 123   ip_alias_init_1,              /* alias_init_1() */
 124   ip_alias_done_1,              /* alias_done_1() */
 125   ip_alias_print_1,             /* alias_print_1() */
 126   NULL                          /* next */
 127 };
 128 
 129 /*
 130  * ip_alias module initialization
 131  */
 132 
 133 int ip_alias_init(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 134 {
 135   return register_net_alias_type(&ip_alias_type, AF_INET);
 136 }
 137 
 138 /*
 139  * ip_alias module done
 140  */
 141 
 142 int ip_alias_done(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 143 {
 144   return unregister_net_alias_type(&ip_alias_type);
 145 }
 146 
 147 #ifdef MODULE
 148 
 149 int init_module(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 150 {
 151   if (ip_alias_init() != 0)
 152     return -EIO;
 153   return 0;
 154 }
 155 
 156 void cleanup_module(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 157 {
 158   if (ip_alias_done() != 0)
 159     printk("ip_alias: can't remove module");
 160 }
 161 
 162 #endif /* MODULE */

/* [previous][next][first][last][top][bottom][index][help] */