patch-1.3.51 linux/net/ipv4/ip_alias.c

Next file: linux/net/ipv4/ip_input.c
Previous file: linux/net/ipv4/igmp.c
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v1.3.50/linux/net/ipv4/ip_alias.c linux/net/ipv4/ip_alias.c
@@ -1,3 +1,21 @@
+/*
+ *		IP_ALIAS (AF_INET) aliasing module.
+ *
+ *
+ * Version:	@(#)ip_alias.c	0.43   12/20/95
+ *
+ * Author:	Juan Jose Ciarlante, <jjciarla@raiz.uncu.edu.ar>
+ *
+ * Fixes:
+ *	JJC	:	ip_alias_dev_select method.
+ *
+ *	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>
@@ -5,6 +23,10 @@
 #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"
@@ -19,7 +41,7 @@
  * AF_INET alias init
  */
 static int 
-ip_alias_init_1(struct net_alias *alias, struct sockaddr *sa)
+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);
@@ -32,7 +54,7 @@
  * AF_INET alias done
  */
 static int
-ip_alias_done_1(struct net_alias *alias)
+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);
@@ -42,11 +64,11 @@
 }
 
 /*
- * print address info
+ * print alias address info
  */
 
 int
-ip_alias_print_1(char *buf, int len, struct net_alias *alias)
+ip_alias_print_1(struct net_alias_type *this, struct net_alias *alias, char *buf, int len)
 {
   char *p;
 
@@ -55,6 +77,37 @@
 		 (p[0] & 255), (p[1] & 255), (p[2] & 255), (p[3] & 255));
 }
 
+struct device *
+ip_alias_dev_select(struct net_alias_type *this, struct device *main_dev, struct sockaddr *sa)
+{
+  __u32 addr;
+  struct rtable *rt;
+  
+  /*
+   * 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
+   */
+
+  rt = ip_rt_route(addr, 0);
+
+  return (rt)? rt->rt_dev : NULL;
+
+}
+
 /*
  * net_alias AF_INET type defn.
  */
@@ -65,7 +118,8 @@
   0,				/* n_attach */
   "ip",				/* name */
   NULL,				/* get_addr32() */
-  NULL,				/* addr_chk() */
+  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() */

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen, slshen@lbl.gov with Sam's (original) version
of this