|
@@ -0,0 +1,209 @@
|
|
|
+/**
|
|
|
+ * Copyright 2015 (C) Orange
|
|
|
+ * <[email protected]>
|
|
|
+ *
|
|
|
+ * This file is part of Kamailio, a free SIP server.
|
|
|
+ *
|
|
|
+ * This file is free software; you can redistribute it and/or modify
|
|
|
+ * it under the terms of the GNU General Public License as published by
|
|
|
+ * the Free Software Foundation; either version 2 of the License, or
|
|
|
+ * (at your option) any later version
|
|
|
+ *
|
|
|
+ *
|
|
|
+ * This file is distributed in the hope that it will be useful,
|
|
|
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
+ * GNU General Public License for more details.
|
|
|
+ *
|
|
|
+ * You should have received a copy of the GNU General Public License
|
|
|
+ * along with this program; if not, write to the Free Software
|
|
|
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
+ *
|
|
|
+ */
|
|
|
+
|
|
|
+
|
|
|
+#include <stdio.h>
|
|
|
+#include <unistd.h>
|
|
|
+#include <stdlib.h>
|
|
|
+#include <string.h>
|
|
|
+
|
|
|
+#include "../../globals.h"
|
|
|
+#include "../../sr_module.h"
|
|
|
+#include "../../tcp_options.h"
|
|
|
+#include "../../dprint.h"
|
|
|
+#include "../../mod_fix.h"
|
|
|
+
|
|
|
+#include "tcpops.h"
|
|
|
+
|
|
|
+MODULE_VERSION
|
|
|
+
|
|
|
+static int mod_init(void);
|
|
|
+static int child_init(int);
|
|
|
+static void mod_destroy(void);
|
|
|
+static int w_tcp_keepalive_enable4(sip_msg_t* msg, char* con, char* idle, char *cnt, char *intvl);
|
|
|
+static int w_tcp_keepalive_enable3(sip_msg_t* msg, char* idle, char *cnt, char *intvl);
|
|
|
+static int w_tcp_keepalive_disable1(sip_msg_t* msg, char* con);
|
|
|
+static int w_tcp_keepalive_disable0(sip_msg_t* msg);
|
|
|
+
|
|
|
+static int fixup_tcp_keepalive_numpv(void** param, int param_no);
|
|
|
+
|
|
|
+
|
|
|
+static cmd_export_t cmds[]={
|
|
|
+ {"tcp_keepalive_enable", (cmd_function)w_tcp_keepalive_enable4, 4, fixup_tcp_keepalive_numpv,
|
|
|
+ 0, ANY_ROUTE},
|
|
|
+ {"tcp_keepalive_enable", (cmd_function)w_tcp_keepalive_enable3, 3, fixup_tcp_keepalive_numpv,
|
|
|
+ 0, REQUEST_ROUTE|ONREPLY_ROUTE},
|
|
|
+ {"tcp_keepalive_disable", (cmd_function)w_tcp_keepalive_disable1, 1, fixup_tcp_keepalive_numpv,
|
|
|
+ 0, ANY_ROUTE},
|
|
|
+ {"tcp_keepalive_disable", (cmd_function)w_tcp_keepalive_disable0, 0, 0,
|
|
|
+ 0, REQUEST_ROUTE|ONREPLY_ROUTE},
|
|
|
+ {0, 0, 0, 0, 0, 0}
|
|
|
+};
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+struct module_exports exports = {
|
|
|
+ "tcpops",
|
|
|
+ DEFAULT_DLFLAGS, /* dlopen flags */
|
|
|
+ cmds, /* exported functions to config */
|
|
|
+ 0, /* exported parameters to config */
|
|
|
+ 0, /* exported statistics */
|
|
|
+ 0, /* exported MI functions */
|
|
|
+ 0, /* exported pseudo-variables */
|
|
|
+ 0, /* extra processes */
|
|
|
+ mod_init, /* module initialization function */
|
|
|
+ 0, /* response function */
|
|
|
+ mod_destroy, /* destroy function */
|
|
|
+ child_init /* per child init function */
|
|
|
+};
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+/**
|
|
|
+ * init module function
|
|
|
+ */
|
|
|
+static int mod_init(void)
|
|
|
+{
|
|
|
+ LM_DBG("TCP keepalive module loaded.\n");
|
|
|
+
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * @brief Initialize async module children
|
|
|
+ */
|
|
|
+static int child_init(int rank)
|
|
|
+{
|
|
|
+
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+/**
|
|
|
+ * destroy module function
|
|
|
+ */
|
|
|
+static void mod_destroy(void)
|
|
|
+{
|
|
|
+ LM_DBG("TCP keepalive module unloaded.\n");
|
|
|
+}
|
|
|
+
|
|
|
+#define _IVALUE_ERROR(NAME) LM_ERR("invalid parameter '" #NAME "' (must be a number)\n")
|
|
|
+#define _IVALUE(NAME)\
|
|
|
+int i_##NAME ;\
|
|
|
+if(fixup_get_ivalue(msg, (gparam_t*)NAME, &( i_##NAME))!=0)\
|
|
|
+{ \
|
|
|
+ _IVALUE_ERROR(NAME);\
|
|
|
+ return -1;\
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+/**
|
|
|
+ *
|
|
|
+ */
|
|
|
+static int w_tcp_keepalive_enable4(sip_msg_t* msg, char* con, char* idle, char *cnt, char *intvl)
|
|
|
+{
|
|
|
+ int fd;
|
|
|
+ int closefd = 0;
|
|
|
+
|
|
|
+ _IVALUE (con)
|
|
|
+
|
|
|
+ if (msg != NULL && msg->rcv.proto_reserved1 == i_con) {
|
|
|
+ if (!get_current_fd(msg->rcv.proto_reserved1, &fd)) {
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (!acquire_fd_from_tcpmain(i_con, &fd)) {
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+ closefd = 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ _IVALUE (idle)
|
|
|
+ _IVALUE (cnt)
|
|
|
+ _IVALUE (intvl)
|
|
|
+
|
|
|
+ return tcp_keepalive_enable(fd, i_idle, i_cnt, i_intvl, closefd);
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+static int w_tcp_keepalive_enable3(sip_msg_t* msg, char* idle, char *cnt, char *intvl)
|
|
|
+{
|
|
|
+ int fd;
|
|
|
+
|
|
|
+ if (msg == NULL) {
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!get_current_fd(msg->rcv.proto_reserved1, &fd)) {
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+
|
|
|
+ _IVALUE (idle)
|
|
|
+ _IVALUE (cnt)
|
|
|
+ _IVALUE (intvl)
|
|
|
+
|
|
|
+ return tcp_keepalive_enable(fd, i_idle, i_cnt, i_intvl, 0);
|
|
|
+}
|
|
|
+
|
|
|
+static int w_tcp_keepalive_disable1(sip_msg_t* msg, char* con)
|
|
|
+{
|
|
|
+ int fd;
|
|
|
+ int closefd = 0;
|
|
|
+
|
|
|
+ _IVALUE (con)
|
|
|
+
|
|
|
+ if (msg != NULL && msg->rcv.proto_reserved1 == i_con) {
|
|
|
+ if (!get_current_fd(msg->rcv.proto_reserved1, &fd)) {
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (!acquire_fd_from_tcpmain(i_con, &fd)) {
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+ closefd = 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ return tcp_keepalive_disable(fd, closefd);
|
|
|
+}
|
|
|
+
|
|
|
+static int w_tcp_keepalive_disable0(sip_msg_t* msg)
|
|
|
+{
|
|
|
+ int fd;
|
|
|
+
|
|
|
+ if (msg == NULL)
|
|
|
+ return -1;
|
|
|
+
|
|
|
+ if (!get_current_fd(msg->rcv.proto_reserved1, &fd)) {
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
+
|
|
|
+ return tcp_keepalive_disable(fd, 0);
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ *
|
|
|
+ */
|
|
|
+static int fixup_tcp_keepalive_numpv(void** param, int param_no)
|
|
|
+{
|
|
|
+ return fixup_igp_null(param, 1);
|
|
|
+}
|
|
|
+
|
|
|
+
|