Revision: 459
          http://vde.svn.sourceforge.net/vde/?rev=459&view=rev
Author:   rd235
Date:     2011-01-14 17:08:05 +0000 (Fri, 14 Jan 2011)

Log Message:
-----------
plugin del bugfix, mgmt of sighup (forwarded to modules/plugins to close/open 
logfiles), better management of port description

Modified Paths:
--------------
    trunk/vde-2/include/vdeplugin.h
    trunk/vde-2/src/lib/libvdeplug.c
    trunk/vde-2/src/vde_switch/consmgmt.c
    trunk/vde-2/src/vde_switch/consmgmt.h
    trunk/vde-2/src/vde_switch/plugins/iplog.c
    trunk/vde-2/src/vde_switch/port.c
    trunk/vde-2/src/vde_switch/vde_switch.c

Modified: trunk/vde-2/include/vdeplugin.h
===================================================================
--- trunk/vde-2/include/vdeplugin.h     2011-01-12 21:24:40 UTC (rev 458)
+++ trunk/vde-2/include/vdeplugin.h     2011-01-14 17:08:05 UTC (rev 459)
@@ -116,6 +116,8 @@
 void printlog(int priority, const char *format, ...);
 
 uid_t port_user(int port);
+char *port_descr(int portno, int epn);
+
 time_t qtime(); // returns global time (faster than time())
 void qtime_csenter();
 void qtime_csexit();

Modified: trunk/vde-2/src/lib/libvdeplug.c
===================================================================
--- trunk/vde-2/src/lib/libvdeplug.c    2011-01-12 21:24:40 UTC (rev 458)
+++ trunk/vde-2/src/lib/libvdeplug.c    2011-01-14 17:08:05 UTC (rev 459)
@@ -130,6 +130,8 @@
        char *std_sockname=NULL;
        char *real_sockname=NULL;
        char *sockname=NULL;
+       char *ssh_client = getenv("SSH_CLIENT");
+       int descrlen;
 
        if (open_args != NULL) {
                if (interface_version == 1) {
@@ -243,9 +245,16 @@
                /* If one of the connect succeeded, we're done */
                if (res == 0)
                {
-                       snprintf(req->description,MAXDESCR,"%s user=%s PID=%d 
%s",
+                       int descrlen=snprintf(req->description,MAXDESCR,"%s 
user=%s PID=%d",
                                        descr,(callerpwd != 
NULL)?callerpwd->pw_name:"??",
-                                       
pid,getenv("SSH_CLIENT")?getenv("SSH_CLIENT"):"");
+                                       pid);
+                       if (ssh_client) {
+                               char *endofip=strchr(ssh_client,' ');
+                               if (endofip) *endofip=0;
+                               
snprintf(req->description+descrlen,MAXDESCR-descrlen,
+                                               " SSH=%s", ssh_client);
+                               if (endofip) *endofip=' ';
+                       }
                        setsockopt(conn->fddata,0,IPN_SO_DESCR,req->description,
                                        strlen(req->description+1));
                        *(conn->inpath.sun_path)=0; /*null string, do not 
delete "return path"*/
@@ -446,10 +455,23 @@
        }
        chmod(conn->inpath.sun_path,mode);
 
-       snprintf(req->description,MAXDESCR,"%s user=%s PID=%d %s SOCK=%s",
+#ifdef DESCR_INCLUDE_SOCK
+       descrlen=snprintf(req->description,MAXDESCR,"%s user=%s PID=%d SOCK=%s",
                        descr,(callerpwd != NULL)?callerpwd->pw_name:"??",
-                       
pid,getenv("SSH_CLIENT")?getenv("SSH_CLIENT"):"",req->sock.sun_path);
+                       pid,req->sock.sun_path);
+#else
+       descrlen=snprintf(req->description,MAXDESCR,"%s user=%s PID=%d",
+                       descr,(callerpwd != NULL)?callerpwd->pw_name:"??", pid);
+#endif
 
+       if (ssh_client) {
+               char *endofip=strchr(ssh_client,' ');
+               if (endofip) *endofip=0;
+               snprintf(req->description+descrlen,MAXDESCR-descrlen," SSH=%s", 
ssh_client);
+               if (endofip) *endofip=' ';
+       }
+
+
        if 
(send(conn->fdctl,req,sizeof(*req)-MAXDESCR+strlen(req->description),0)<0) 
                goto abort;
 

Modified: trunk/vde-2/src/vde_switch/consmgmt.c
===================================================================
--- trunk/vde-2/src/vde_switch/consmgmt.c       2011-01-12 21:24:40 UTC (rev 
458)
+++ trunk/vde-2/src/vde_switch/consmgmt.c       2011-01-14 17:08:05 UTC (rev 
459)
@@ -12,6 +12,7 @@
 #include <unistd.h>
 #include <syslog.h>
 #include <stdlib.h>
+#include <signal.h>
 #include <grp.h>
 #include <libgen.h>
 #include <sys/types.h>
@@ -64,9 +65,11 @@
 static struct dbgcl **dbgclt=&dbgclh;
 #define MGMTPORTNEW (dl) 
 #define MGMTPORTDEL (dl+1) 
+#define MGMTSIGHUP (dl+2) 
 static struct dbgcl dl[]= {
        {"mgmt/+",NULL,D_MGMT|D_PLUS},
-       {"mgmt/-",NULL,D_MGMT|D_MINUS}
+       {"mgmt/-",NULL,D_MGMT|D_MINUS},
+       {"sig/hup",NULL,D_SIG|D_HUP}
 };
 #endif
 #ifdef VDEPLUGIN
@@ -140,7 +143,7 @@
 
 void delplugin(struct plugin *cl)
 {
-       register struct plugin **p=&pluginh;
+       register struct plugin **p=plugint=&pluginh;
        while (*p != NULL) {
                if (*p == cl)
                        *p=cl->next;
@@ -861,6 +864,11 @@
 #endif
 };
 
+static void sighupmgmt(int signo)
+{
+       EVENTOUT(MGMTSIGHUP, signo);
+}
+
 void start_consmgmt(void)
 {
        swmi.swmname="console-mgmt";
@@ -876,4 +884,7 @@
        ADDDBGCL(dl);
 #endif
        add_swm(&swmi);
+#ifdef DEBUGOPT
+       signal(SIGHUP,sighupmgmt);
+#endif
 }

Modified: trunk/vde-2/src/vde_switch/consmgmt.h
===================================================================
--- trunk/vde-2/src/vde_switch/consmgmt.h       2011-01-12 21:24:40 UTC (rev 
458)
+++ trunk/vde-2/src/vde_switch/consmgmt.h       2011-01-14 17:08:05 UTC (rev 
459)
@@ -33,6 +33,7 @@
 #ifdef DEBUGOPT
 #define D_PACKET 01000
 #define D_MGMT 02000
+#define D_SIG 03000
 #define D_IN 01
 #define D_OUT 02
 #define D_PLUS 01
@@ -44,6 +45,7 @@
 #define D_PORT 020
 #define D_EP 030
 #define D_FSTP 040
+#define D_HUP 01
 struct dbgcl {
        char *path; /* debug path for add/del */
        char *help; /* help string. just event mgmt when NULL */

Modified: trunk/vde-2/src/vde_switch/plugins/iplog.c
===================================================================
--- trunk/vde-2/src/vde_switch/plugins/iplog.c  2011-01-12 21:24:40 UTC (rev 
458)
+++ trunk/vde-2/src/vde_switch/plugins/iplog.c  2011-01-14 17:08:05 UTC (rev 
459)
@@ -187,7 +187,7 @@
                e->port=port;
                e->vlan = vlan;
                char hostname[100];
-               char msg[256];
+               char msg[1024];
                char lf[]="\n";
                char stime[26];
                struct iovec iov[]={{stime+4,16},{msg,0},{lf,1}};
@@ -196,12 +196,19 @@
                                (len==16 && ip62string((uint32_t 
*)addr,hostname,sizeof(hostname))==0)) {
                        struct passwd *pwd;
                        char *username;
+                       int epn;
+                       char *descr;
                        if ((pwd=getpwuid(port_user(port))) == NULL)
                                username="(none)";
                        else
                                username=pwd->pw_name;
                        iov[1].iov_len=snprintf(msg,sizeof(msg),"ipv%d %s 
port=%d vlan=%d user=%s",
                                        (len==4)?4:6, hostname, port, vlan, 
username);
+                       for (epn=0; (descr=port_descr(port,epn)) != NULL; 
epn++) {
+                               int len=iov[1].iov_len;
+                               int descrlen=snprintf(msg+len,sizeof(msg)-len," 
\"%s\"",descr);
+                               iov[1].iov_len+=descrlen;
+                       }
                        if (logfilefd >= 0) {
                                time_t ntime=time(&ntime);
                                ctime_r(&ntime,stime);
@@ -725,6 +732,25 @@
        {"iplog/ipsearch","ipaddr","search an IP 
address",iplog_ipsearch,STRARG|WITHFILE},
 };
 
+static int iplog_hup(struct dbgcl *event,void *arg,va_list v)
+{
+       if (logfilefd >= 0) {
+               char stime[26];
+               char lf[]="\n";
+               char *prehup="SIGHUP: closing file";
+               char *posthup="SIGHUP: opening file";
+               struct iovec 
preiov[]={{stime+4,16},{prehup,strlen(prehup)},{lf,1}};
+               struct iovec 
postiov[]={{stime+4,16},{posthup,strlen(posthup)},{lf,1}};
+               time_t ntime=time(&ntime);
+               ctime_r(&ntime,stime);
+               writev(logfilefd,preiov,3);
+               close(logfilefd);
+               logfilefd=open(logfile,O_CREAT|O_WRONLY|O_APPEND,0600);
+               writev(logfilefd,postiov,3);
+       }
+       return 0;
+}
+
        static void
        __attribute__ ((constructor))
 init (void)
@@ -733,9 +759,9 @@
        ADDCL(cl);
        ADDDBGCL(dl);
        ip_gc_timerno=qtimer_add(ip_gc_interval,0,ip_hash_gc,NULL);
+       eventadd(iplog_hup, "sig/hup", NULL);
        eventadd(iplog_pktin, "packet/in", NULL);
        eventadd(iplog_port_minus, "port/-", NULL);
-       /* XXX add event port/minux  */
 }
 
        static void
@@ -743,8 +769,10 @@
 fini (void)
 {
        time_t t = qtime();
+       closelogfile();
        eventdel(iplog_port_minus, "port/-", NULL);
        eventdel(iplog_pktin, "packet/in", NULL);
+       eventdel(iplog_hup, "sig/hup", NULL);
        qtimer_del(ip_gc_timerno);
        DELCL(cl);
        DELDBGCL(dl);

Modified: trunk/vde-2/src/vde_switch/port.c
===================================================================
--- trunk/vde-2/src/vde_switch/port.c   2011-01-12 21:24:40 UTC (rev 458)
+++ trunk/vde-2/src/vde_switch/port.c   2011-01-14 17:08:05 UTC (rev 459)
@@ -1197,12 +1197,31 @@
 
 uid_t port_user(int port)
 {
-       if (port<0 || port>=numports)
+       if (port<0 || port>=numports || portv[port]==NULL)
                return -1;
        else
                return portv[port]->curuser;
 }
 
+char *port_descr(int portno, int epn) {
+       if (portno<0 || portno>=numports)
+               return NULL;
+       else {
+               struct port *port=portv[portno];
+               if (port == NULL)
+                       return NULL;
+               else {
+                       struct endpoint *ep;
+                       for (ep=port->ep;ep!=NULL && epn>0;ep=ep->next,epn--)
+                               ;
+                       if (ep)
+                               return ep->descr;
+                       else
+                               return NULL;
+               }
+       }
+}
+
 static struct comlist cl[]={
        {"port","============","PORT STATUS MENU",NULL,NOARG},
        {"port/showinfo","","show port info",showinfo,NOARG|WITHFILE},

Modified: trunk/vde-2/src/vde_switch/vde_switch.c
===================================================================
--- trunk/vde-2/src/vde_switch/vde_switch.c     2011-01-12 21:24:40 UTC (rev 
458)
+++ trunk/vde-2/src/vde_switch/vde_switch.c     2011-01-14 17:08:05 UTC (rev 
459)
@@ -535,10 +535,10 @@
 int main(int argc, char **argv)
 {
        set_switchmac();
+       setsighandlers();
        start_modules();
        parse_args(argc,argv);
        atexit(cleanup);
-       setsighandlers();
        hash_init(hash_size);
 #ifdef FSTP
        fst_init(numports);


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
Protect Your Site and Customers from Malware Attacks
Learn about various malware tactics and how to avoid them. Understand 
malware threats, the impact they can have on your business, and how you 
can protect your company and customers by using code signing.
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
vde-users mailing list
vde-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/vde-users

Reply via email to