Re: [PATCH] Llimit smsbox listener to specific interface

Roman Shterenzon <[email protected]>
Newsgroups gmane.comp.mobile.kannel.devel
Message-ID <[email protected]>
No problem



________________________________
From: Alexander Malysh <[email protected]>
To: Rene Kluwen <[email protected]>
Cc: 'Roman Shterenzon' <[email protected]>; 'Devel Kannel' <[email protected]>
Sent: Thursday, April 7, 2011 2:47 PM
Subject: Re: [PATCH] Llimit smsbox listener to specific interface


because it was not needed :-)

@Roman: could you please kill typedef?


Thanks,
Alexander Malysh


Am 07.04.2011 um 13:24 schrieb Rene Kluwen:

+1. I wondered before already why something so simple was not implemented.
> 
>From: [email protected] [mailto:[email protected]] On Behalf Of Roman Shterenzon
>Sent: Thursday, 07 April, 2011 01:38
>To: Devel Kannel
>Subject: [PATCH] Llimit smsbox listener to specific interface
> 
>Hi,
> 
>Attached is a patch which provides support for limiting listening for smsbox connections to specific interface, e.g.
> 
>group = core
>smsbox-interface = "127.0.0.1"
> 
>If it's omitted, then the original behavior is exhibited.
> 
>Your feedback is appreciated!
> 
>--Roman
>P.S. I noticed that smsbox-interface parameter is missing from the manual.
smsbox_iface.diff (application/octet-stream, 2.6 KB)
diff --git a/gw/bb_boxc.c b/gw/bb_boxc.c
index b978435..6943e3f 100644
--- a/gw/bb_boxc.c
+++ b/gw/bb_boxc.c
@@ -117,6 +117,8 @@ static int smsbox_port_ssl;
 static long	wapbox_port;
 static int wapbox_port_ssl;
 
+static Octstr *smsbox_interface = NULL;
+
 /* max pending messages on the line to smsbox */
 static long smsbox_max_pending;
 
@@ -148,6 +150,10 @@ typedef struct _boxc {
     volatile int routable;
 } Boxc;
 
+struct ConnParams {
+    int port;
+    Octstr *interface;
+};
 
 /* forward declaration */
 static void sms_to_smsboxes(void *arg);
@@ -993,17 +999,17 @@ static void wait_for_connections(int fd, void (*function) (void *arg),
 static void smsboxc_run(void *arg)
 {
     int fd;
-    int port;
+    struct ConnParams *params = (struct ConnParams*)arg;
 
     gwlist_add_producer(flow_threads);
     gwthread_wakeup(MAIN_THREAD_ID);
-    port = (int) *((long *)arg);
 
-    fd = make_server_socket(port, NULL);
-    /* XXX add interface_name if required */
+    fd = make_server_socket(params->port, params->interface ? octstr_get_cstr(params->interface) : NULL);
+    octstr_destroy(params->interface);
+    gw_free(params);
 
     if (fd < 0) {
-        panic(0, "Could not open smsbox port %d", port);
+        panic(0, "Could not open smsbox port %d", params->port);
     }
 
     /*
@@ -1222,6 +1228,8 @@ int smsbox_start(Cfg *cfg)
     if (smsbox_port_ssl)
         debug("bb", 0, "smsbox connection module is SSL-enabled");
 
+    smsbox_interface = cfg_get(grp, octstr_imm("smsbox-interface"));
+
     if (cfg_get_integer(&smsbox_max_pending, grp, octstr_imm("smsbox-max-pending")) == -1) {
         smsbox_max_pending = SMSBOX_MAX_PENDING;
         info(0, "BOXC: 'smsbox-max-pending' not set, using default (%ld).", smsbox_max_pending);
@@ -1258,7 +1266,11 @@ int smsbox_start(Cfg *cfg)
     if ((sms_dequeue_thread = gwthread_create(sms_to_smsboxes, NULL)) == -1)
  	    panic(0, "Failed to start a new thread for smsbox routing");
 
-    if (gwthread_create(smsboxc_run, &smsbox_port) == -1)
+    struct ConnParams *params = gw_malloc(sizeof(struct ConnParams));
+    gw_assert(params != NULL);
+    params->port = smsbox_port;
+    params->interface = smsbox_interface;
+    if (gwthread_create(smsboxc_run, params) == -1)
 	    panic(0, "Failed to start a new thread for smsbox connections");
 
     return 0;
diff --git a/gwlib/cfg.def b/gwlib/cfg.def
index 0baca5d..d6b9f82 100644
--- a/gwlib/cfg.def
+++ b/gwlib/cfg.def
@@ -84,6 +84,7 @@ SINGLE_GROUP(core,
     OCTSTR(admin-allow-ip)
     OCTSTR(smsbox-port)
     OCTSTR(smsbox-port-ssl)
+    OCTSTR(smsbox-interface)
     OCTSTR(smsbox-max-pending)
     OCTSTR(wapbox-port)
     OCTSTR(wapbox-port-ssl)
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.