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  
  44 static int 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  
  57 static int 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 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] */
  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)
     /* [previous][next][first][last][top][bottom][index][help] */
  80 {
  81         __u32 addr;
  82         struct rtable *rt;
  83         struct device *dev=NULL;
  84   
  85         /*
  86          *      Defensive...    
  87          */
  88   
  89         if (main_dev == NULL) 
  90                 return NULL;
  91 
  92         /*
  93          *      Get u32 address. 
  94          */
  95 
  96         addr =  (sa)? (*(struct sockaddr_in *)sa).sin_addr.s_addr : 0;
  97         if (addr == 0)
  98                 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         if(rt)
 107         {
 108                 dev=rt->rt_dev;
 109                 ip_rt_put(rt);
 110         }
 111         return dev;
 112 }
 113 
 114 /*
 115  * net_alias AF_INET type defn.
 116  */
 117 
 118 struct net_alias_type ip_alias_type =
 119 {
 120         AF_INET,                /* type */
 121         0,                      /* n_attach */
 122         "ip",                   /* name */
 123         NULL,                   /* get_addr32() */
 124         NULL,                   /* dev_addr_chk() */
 125         ip_alias_dev_select,    /* dev_select() */
 126         ip_alias_init_1,        /* alias_init_1() */
 127         ip_alias_done_1,        /* alias_done_1() */
 128         ip_alias_print_1,       /* alias_print_1() */
 129         NULL                    /* next */
 130 };
 131 
 132 /*
 133  * ip_alias module initialization
 134  */
 135 
 136 int ip_alias_init(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 137 {
 138         return register_net_alias_type(&ip_alias_type, AF_INET);
 139 }
 140 
 141 /*
 142  * ip_alias module done
 143  */
 144 
 145 int ip_alias_done(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 146 {
 147         return unregister_net_alias_type(&ip_alias_type);
 148 }
 149 
 150 #ifdef MODULE
 151 
 152 int init_module(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 153 {
 154         if (ip_alias_init() != 0)
 155                 return -EIO;
 156         return 0;
 157 }
 158 
 159 void cleanup_module(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 160 {
 161         if (ip_alias_done() != 0)
 162                 printk("ip_alias: can't remove module");
 163 }
 164 
 165 #endif /* MODULE */

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