LVS
lvs-users
Google
 
Web LinuxVirtualServer.org

[PATCH] Auto load ip_vs_ftp helper module

To: lvs-users@xxxxxxxxxxxxxxxxxxxxxx
Subject: [PATCH] Auto load ip_vs_ftp helper module
From: Horms <horms@xxxxxxxxxxxx>
Date: Thu, 9 Oct 2003 11:46:48 +0900
As per some discussions earlier in the week with Joe and others here is
a patch to try and auto load the ip_vs_ftp module if a real server is
added which uses LVS-NAT and the vport is 23.

N.B: There are lots of times when this won't work, for example if you
are using fwmark virtual services.  But it should handle the simple case
where a ip/port LVS-MASQ virtual service needs ip_vs_ftp.

I decided to do this in ipvsadm rather than the kernel code as there is
no natrual dependancy for the kernel code to work with so it seemed
better to handle it in user space.  Also the change in user space was
very easy. Easy is good :)

Perhaps putting this in the kernel would allow us to catch fwmark
virtual services. But my feeling is that if you have worked out how to
use fwmarks then working out that you need ip_vs_ftp should be pretty
straight forward.

-- 
Horms


diff -rup ipvs-1.0.10/ipvs/ip_vs.h ipvs-1.0.10.new/ipvs/ip_vs.h
--- ipvs-1.0.10/ipvs/ip_vs.h    2003-07-19 20:09:48.000000000 +0900
+++ ipvs-1.0.10.new/ipvs/ip_vs.h        2003-10-09 11:09:16.000000000 +0900
@@ -218,6 +218,13 @@
 };
 
 
+/*
+ *      The port number of FTP service (in host order).
+ */
+#define HFTPPORT  21
+#define HFTPDATA  20
+
+
 #ifdef __KERNEL__
 
 #include <linux/config.h>
@@ -283,8 +290,8 @@
 /*
  *      The port number of FTP service (in network order).
  */
-#define FTPPORT  __constant_htons(21)
-#define FTPDATA  __constant_htons(20)
+#define FTPPORT  __constant_htons(HFTPPORT)
+#define FTPDATA  __constant_htons(HFTPDATA)
 
 
 /*
diff -rup ipvs-1.0.10/ipvs/ipvsadm/ipvsadm.c 
ipvs-1.0.10.new/ipvs/ipvsadm/ipvsadm.c
--- ipvs-1.0.10/ipvs/ipvsadm/ipvsadm.c  2003-04-11 23:02:38.000000000 +0900
+++ ipvs-1.0.10.new/ipvs/ipvsadm/ipvsadm.c      2003-10-09 11:36:28.000000000 
+0900
@@ -271,10 +271,12 @@
 static void list_timeout(void);
 static void list_daemon(void);
 
-static int modprobe_ipvs(void);
+static int modprobe_module(char *name);
 static void check_ipvs_version(void);
 static int process_options(int argc, char **argv, int reading_stdin);
 
+#define IPVS_MODULE     "ip_vs"
+#define IPVS_FTP_MODULE "ip_vs_ftp"
 
 int main(int argc, char **argv)
 {
@@ -282,7 +284,7 @@ int main(int argc, char **argv)
 
        if (ipvs_init()) {
                /* try to insmod the ip_vs module if ipvs_init failed */
-               if (modprobe_ipvs() || ipvs_init())
+               if (modprobe_module(IPVS_MODULE) || ipvs_init())
                        fail(2, "Can't initialize ipvs: %s\n"
                                "Are you sure that IP Virtual Server is "
                                "built in the kernel or as module?",
@@ -904,6 +906,16 @@ static int process_options(int argc, cha
                    (urule.conn_flags == IP_VS_CONN_F_TUNNEL
                     || urule.conn_flags == IP_VS_CONN_F_DROUTE))
                        urule.dport = urule.vport;
+
+               /* try to insmod the ip_vs_ftp module if service is for
+                * port 23 if IP_VS_CONN_F_MASQ is used. */
+               if(urule.vport == htons(HFTPPORT) && 
+                               urule.conn_flags == IP_VS_CONN_F_MASQ && 
+                               modprobe_module(IPVS_FTP_MODULE))
+                       fprintf(stderr, "Warning: "
+                               "Can't initialize ip_vs_ftp module "
+                               "for port %d virtual service\n",
+                               HFTPPORT);
        }
 
        result = ipvs_command(cmd, &urule);
@@ -1216,9 +1228,9 @@
 }
 
 
-static int modprobe_ipvs(void)
+static int modprobe_module(char *name)
 {
-       char *argv[] = { "/sbin/modprobe", "-s", "-k", "--", "ip_vs", NULL };
+       char *argv[] = { "/sbin/modprobe", "-s", "-k", "--", name, NULL };
        int child;
        int status;
        int rc;
<Prev in Thread] Current Thread [Next in Thread>