]> git.ipfire.org Git - people/ms/suricata.git/commitdiff
af-packet: Add option to disable promiscuous mode
authorEric Leblond <eric@regit.org>
Fri, 2 Sep 2011 09:02:32 +0000 (11:02 +0200)
committerVictor Julien <victor@inliniac.net>
Thu, 8 Sep 2011 09:14:21 +0000 (11:14 +0200)
This patch adds an option to suricata.yaml to be able to disable
the switch of the interface into promiscuous mode.

src/runmode-af-packet.c
src/source-af-packet.c
src/source-af-packet.h
suricata.yaml

index d7da0b2c1a083008b9790bf8621f9dd1bbada93c..84e30e9df33850cf77df8e520e3e31caae6d973e 100644 (file)
@@ -96,6 +96,7 @@ AFPIfaceConfig *ParseAFPConfig(char *iface)
     char *tmpclusterid;
     char *tmpctype;
     intmax_t value;
+    int dispromisc;
 
     if (aconf == NULL) {
         return NULL;
@@ -105,6 +106,7 @@ AFPIfaceConfig *ParseAFPConfig(char *iface)
     aconf->buffer_size = 0;
     aconf->cluster_id = 1;
     aconf->cluster_type = PACKET_FANOUT_HASH;
+    aconf->promisc = 1;
 
     /* Find initial node */
     af_packet_node = ConfGetNode("af-packet");
@@ -172,6 +174,13 @@ AFPIfaceConfig *ParseAFPConfig(char *iface)
         aconf->buffer_size = 0;
     }
 
+    ConfGetChildValueBool(if_root, "disable-promisc", (int *)&dispromisc);
+    if (dispromisc) {
+        SCLogInfo("Disabling promiscuous mode on iface %s",
+                aconf->iface);
+        aconf->promisc = 0;
+    }
+
     return aconf;
 }
 
index 789282890ae3109d6b60659572adcb96c31eca5b..9a6211eb6142cf697e5fe8f0f8a23614d215d96d 100644 (file)
@@ -153,6 +153,7 @@ typedef struct AFPThreadVars_
 
     /* socket buffer size */
     int buffer_size;
+    int promisc;
 
     int cluster_id;
     int cluster_type;
@@ -647,18 +648,20 @@ static int AFPCreateSocket(AFPThreadVars *ptv, char *devname, int verbose)
         close(ptv->socket);
         return -1;
     }
-    /* Force promiscuous mode */
-    memset(&sock_params, 0, sizeof(sock_params));
-    sock_params.mr_type = PACKET_MR_PROMISC;
-    sock_params.mr_ifindex = bind_address.sll_ifindex;
-    r = setsockopt(ptv->socket, SOL_PACKET, PACKET_ADD_MEMBERSHIP,(void *)&sock_params, sizeof(sock_params));
-    if (r < 0) {
-        SCLogError(SC_ERR_AFP_CREATE,
-                   "Couldn't switch iface %s to promiscuous, error %s",
-                   devname,
-                   strerror(errno));
-        close(ptv->socket);
-        return -1;
+    if (ptv->promisc != 0) {
+        /* Force promiscuous mode */
+        memset(&sock_params, 0, sizeof(sock_params));
+        sock_params.mr_type = PACKET_MR_PROMISC;
+        sock_params.mr_ifindex = bind_address.sll_ifindex;
+        r = setsockopt(ptv->socket, SOL_PACKET, PACKET_ADD_MEMBERSHIP,(void *)&sock_params, sizeof(sock_params));
+        if (r < 0) {
+            SCLogError(SC_ERR_AFP_CREATE,
+                    "Couldn't switch iface %s to promiscuous, error %s",
+                    devname,
+                    strerror(errno));
+            close(ptv->socket);
+            return -1;
+        }
     }
     /* set socket recv buffer size */
     if (ptv->buffer_size != 0) {
@@ -739,6 +742,8 @@ TmEcode ReceiveAFPThreadInit(ThreadVars *tv, void *initdata, void **data) {
 
     ptv->buffer_size = afpconfig->buffer_size;
 
+    ptv->promisc = afpconfig->promisc;
+
     ptv->threads = 1;
 #ifdef HAVE_PACKET_FANOUT
     ptv->cluster_type = PACKET_FANOUT_LB;
index 7c3b529ad9a30aed285e68f8e9d0529aac3bce3c..2a3df30fb41494ac724d913039298be24375c758 100644 (file)
@@ -49,6 +49,8 @@ typedef struct AFPIfaceConfig_
     /* cluster param */
     int cluster_id;
     int cluster_type;
+    /* promisc mode */
+    int promisc;
 } AFPIfaceConfig;
 
 void TmModuleReceiveAFPRegister (void);
index bd832750c5d75185ccb6b49449c8b030a3a98218..369e874b5979d2ba127e253613807c09da8c868d 100644 (file)
@@ -177,12 +177,15 @@ af-packet:
     defrag: yes
     # recv buffer size, increase value could improve performance
     # buffer-size: 32768
+    # Set to yes to disable promiscuous mode
+    # disable-promisc: no
   - interface: eth1
     threads: 1
     cluster-id: 98
     cluster-type: cluster_round_robin
     defrag: yes
     # buffer-size: 32768
+    # disable-promisc: no
 
 defrag:
   max-frags: 65535