summaryrefslogtreecommitdiff
path: root/src/mcast.c
diff options
context:
space:
mode:
authorPablo Neira Ayuso <pablo@netfilter.org>2008-05-20 15:52:06 +0200
committerPablo Neira Ayuso <pablo@netfilter.org>2008-05-20 15:52:06 +0200
commitda8717a4bfa8884a411ae2445b9f1654b0550a64 (patch)
treeb04f02da10caf6d94e61d0d1496b8fd6f1573739 /src/mcast.c
parentdb91cafe5b72f9f591dd8c168427005503186c01 (diff)
downloadconntrack-tools-da8717a4bfa8884a411ae2445b9f1654b0550a64.tar.gz
conntrack-tools-da8717a4bfa8884a411ae2445b9f1654b0550a64.zip
add Mcast[Snd|Rcv]SocketBuffer clauses to tune multicast socket buffers
Diffstat (limited to 'src/mcast.c')
-rw-r--r--src/mcast.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/mcast.c b/src/mcast.c
index f945511..16d8856 100644
--- a/src/mcast.c
+++ b/src/mcast.c
@@ -28,6 +28,7 @@
#include <string.h>
#include <sys/ioctl.h>
#include <net/if.h>
+#include <errno.h>
struct mcast_sock *mcast_server_create(struct mcast_conf *conf)
{
@@ -37,6 +38,7 @@ struct mcast_sock *mcast_server_create(struct mcast_conf *conf)
struct ipv6_mreq ipv6;
} mreq;
struct mcast_sock *m;
+ socklen_t socklen = sizeof(int);
m = (struct mcast_sock *) malloc(sizeof(struct mcast_sock));
if (!m)
@@ -96,6 +98,20 @@ struct mcast_sock *mcast_server_create(struct mcast_conf *conf)
return NULL;
}
+ if (conf->rcvbuf &&
+ setsockopt(m->fd, SOL_SOCKET, SO_RCVBUFFORCE, &conf->rcvbuf,
+ sizeof(int)) == -1) {
+ /* not supported in linux kernel < 2.6.14 */
+ if (errno != ENOPROTOOPT) {
+ debug("mcast_sock_server_create:setsockopt2");
+ close(m->fd);
+ free(m);
+ return NULL;
+ }
+ }
+
+ getsockopt(m->fd, SOL_SOCKET, SO_RCVBUF, &conf->rcvbuf, &socklen);
+
if (bind(m->fd, (struct sockaddr *) &m->addr, m->sockaddr_len) == -1) {
debug("mcast_sock_server_create:bind");
close(m->fd);
@@ -195,6 +211,7 @@ struct mcast_sock *mcast_client_create(struct mcast_conf *conf)
{
int ret;
struct mcast_sock *m;
+ socklen_t socklen = sizeof(int);
m = (struct mcast_sock *) malloc(sizeof(struct mcast_sock));
if (!m)
@@ -215,6 +232,20 @@ struct mcast_sock *mcast_client_create(struct mcast_conf *conf)
return NULL;
}
+ if (conf->sndbuf &&
+ setsockopt(m->fd, SOL_SOCKET, SO_SNDBUFFORCE, &conf->sndbuf,
+ sizeof(int)) == -1) {
+ /* not supported in linux kernel < 2.6.14 */
+ if (errno != ENOPROTOOPT) {
+ debug("mcast_sock_server_create:setsockopt2");
+ close(m->fd);
+ free(m);
+ return NULL;
+ }
+ }
+
+ getsockopt(m->fd, SOL_SOCKET, SO_SNDBUF, &conf->sndbuf, &socklen);
+
switch(conf->ipproto) {
case AF_INET:
ret = __mcast_client_create_ipv4(m, conf);