Useful to identify sessions handled by OpenL2TP among others.

Signed-off-by: Benjamin Cama <[email protected]>
---
 doc/l2tpconfig.1    |    2 ++
 l2tp_api.c          |    1 +
 l2tp_common.c       |    3 +++
 l2tp_config.c       |   23 +++++++++++++++++++++--
 l2tp_config_parse.y |   13 +++++++++++++
 l2tp_config_token.l |    1 +
 l2tp_ppp.c          |   37 +++++++++++++++++++++++++++++++++++++
 l2tp_rpc.x          |    3 +++
 plugins/ppp_unix.c  |    6 ++++++
 9 files changed, 87 insertions(+), 2 deletions(-)

diff --git a/doc/l2tpconfig.1 b/doc/l2tpconfig.1
index c77940f..7b7916b 100644
--- a/doc/l2tpconfig.1
+++ b/doc/l2tpconfig.1
@@ -507,6 +507,8 @@ local_name               - Name to use for authentication 
with the
                            peer, unless overridden by user_name.
 remote_name              - Name to assume for the remote peer for
                            authentication purposes.
+ipparam                  - String passed as extra parameter to ip-up/down
+                           scripts.
 .fi
 .SS PPP PROFILE LIST
 .nf
diff --git a/l2tp_api.c b/l2tp_api.c
index d16f80e..bd8097e 100644
--- a/l2tp_api.c
+++ b/l2tp_api.c
@@ -239,6 +239,7 @@ static void l2tp_api_xdr_free_ppp_profile_msg_data(caddr_t 
addr)
        if (OPTSTRING_PTR(msg->radius_hint) != NULL) 
free(OPTSTRING(msg->radius_hint));
        if (OPTSTRING_PTR(msg->local_name) != NULL) 
free(OPTSTRING(msg->local_name));
        if (OPTSTRING_PTR(msg->remote_name) != NULL) 
free(OPTSTRING(msg->remote_name));
+       if (OPTSTRING_PTR(msg->ipparam) != NULL) free(OPTSTRING(msg->ipparam));
 }
 
 static void l2tp_api_xdr_free_ppp_profile_list_msg_data(caddr_t addr)
diff --git a/l2tp_common.c b/l2tp_common.c
index 2caf9a9..0650ce5 100644
--- a/l2tp_common.c
+++ b/l2tp_common.c
@@ -938,6 +938,9 @@ int l2tp_show_ppp_profile(FILE *file, struct 
l2tp_api_ppp_profile_msg_data *pp)
        }
        len += fprintf(file, "  multilink: %s, proxy arp: %s\n", 
                       pp->multilink ? "YES" : "NO", pp->proxy_arp ? "YES" : 
"NO");
+       if (OPTSTRING_PTR(pp->ipparam) != NULL) {
+               len += fprintf(file, "  ipparam: %s\n", OPTSTRING(pp->ipparam));
+       }
        len += fprintf(file, "  IP parameters:-\n");
        ip_to_string(&local_ip[0], pp->local_ip_addr.s_addr);
        ip_to_string(&peer_ip[0], pp->peer_ip_addr.s_addr);
diff --git a/l2tp_config.c b/l2tp_config.c
index d1aec91..8ef0121 100644
--- a/l2tp_config.c
+++ b/l2tp_config.c
@@ -3129,6 +3129,7 @@ typedef enum {
        L2TP_PPP_ARGID_IPV6CP_MAX_TERM_REQS,
        L2TP_PPP_ARGID_IPV6CP_RETX_INTVL,
        L2TP_PPP_ARGID_IPCP_ENABLE,
+       L2TP_PPP_ARGID_IPPARAM,
 } l2tp_ppp_arg_ids_t;
  
 #undef ARG
@@ -3201,7 +3202,8 @@ typedef enum {
                                                                         
"config-rejects instead. Default=10.")),                                       \
        ARG(IPV6CP_MAX_TERM_REQS,"ipv6cp_max_terminate_requests", 0, int32, 
"Maximum number of IPv6CP term-requests to send. Default=3."),              \
        ARG(IPV6CP_RETX_INTVL,  "ipv6cp_retransmit_interval", 0, int32, "IPv6CP 
retransmission timeout. Default=3."),                                   \
-       ARG(IPCP_ENABLE,        "ipcp_enable",          0,      bool,   "Enable 
IPCP")
+       ARG(IPCP_ENABLE,        "ipcp_enable",          0,      bool,   "Enable 
IPCP"),                                                                 \
+       ARG(IPPARAM,            "ipparam",              0,      string, "String 
passed as extra parameter to ip-up/down scripts")
 
 
 static struct cli_arg_entry l2tp_args_ppp_profile_create[] = {
@@ -3289,6 +3291,7 @@ static struct cli_arg_entry l2tp_args_ppp_profile_unset[] 
= {
        FLG(IPV6CP_MAX_TERM_REQS,"ipv6cp_max_terminate_requests", "Maximum 
number of IPv6CP term-requests to send. Default=3."),        \
        FLG(IPV6CP_RETX_INTVL,  "ipv6cp_retransmit_interval", "IPv6CP 
retransmission timeout. Default=3."),                             \
        FLG(IPCP_ENABLE,        "ipcp_enable",          "Enable IPCP"),         
                                                \
+       FLG(IPPARAM,            "ipparam",              "String passed as extra 
parameter to ip-up/down scripts"),                      \
        { NULL, },
 };
 
@@ -3530,6 +3533,15 @@ static int l2tp_parse_ppp_profile_arg(l2tp_ppp_arg_ids_t 
arg_id, struct cli_node
                L2TP_ACT_PARSE_ARG(arg, arg_value, ints[0], msg->flags2, 
L2TP_API_PPP_PROFILE_FLAG_IPCP_ENABLE);
                msg->ipcp_enable = ints[0];
                break;
+       case L2TP_PPP_ARGID_IPPARAM:
+               OPTSTRING(msg->ipparam) = strdup(arg_value);
+               if (OPTSTRING(msg->ipparam) == NULL) {
+                       result = -ENOMEM;
+                       goto out;
+               }
+               msg->ipparam.valid = 1;
+               msg->flags2 |= L2TP_API_PPP_PROFILE_FLAG_IPPARAM;
+               break;
        }
 
        result = 0;
@@ -3916,6 +3928,9 @@ static int l2tp_act_ppp_profile_unset(struct cli_node 
*node, int argc, char *arg
                case L2TP_PPP_ARGID_IPCP_ENABLE:
                        msg.flags2 |= L2TP_API_PPP_PROFILE_FLAG_IPCP_ENABLE;
                        break;
+               case L2TP_PPP_ARGID_IPPARAM:
+                       msg.flags2 |= L2TP_API_PPP_PROFILE_FLAG_IPPARAM;
+                       break;
                }
        } L2TP_ACT_END();
 
@@ -4939,7 +4954,8 @@ static void l2tp_config_dump_ppp_profile(FILE *file, 
struct l2tp_api_ppp_profile
                            L2TP_API_PPP_PROFILE_FLAG_IPV6CP_MAX_CONFIG_NAKS |
                            
L2TP_API_PPP_PROFILE_FLAG_IPV6CP_MAX_TERMINATE_REQUESTS |
                            
L2TP_API_PPP_PROFILE_FLAG_IPV6CP_RETRANSMIT_INTERVAL |
-                           L2TP_API_PPP_PROFILE_FLAG_IPCP_ENABLE))) {
+                           L2TP_API_PPP_PROFILE_FLAG_IPCP_ENABLE |
+                           L2TP_API_PPP_PROFILE_FLAG_IPPARAM))) {
  
                fprintf(file, "ppp profile modify profile_name=%s \\\n", 
cfg->profile_name);
 
@@ -5112,6 +5128,9 @@ static void l2tp_config_dump_ppp_profile(FILE *file, 
struct l2tp_api_ppp_profile
                if (cfg->flags2 & L2TP_API_PPP_PROFILE_FLAG_IPCP_ENABLE) {
                        fprintf(file, "\tipcp_enable=%s \\\n", 
Y_OR_N(cfg->ipcp_enable));
                }
+               if (cfg->flags2 & L2TP_API_PPP_PROFILE_FLAG_IPPARAM && 
(OPTSTRING_PTR(cfg->ipparam) != NULL)) {
+                       fprintf(file, "\tipparam=%s \\\n", 
OPTSTRING_PTR(cfg->ipparam));
+               }
                fprintf(file, "\n");
        }
 }
diff --git a/l2tp_config_parse.y b/l2tp_config_parse.y
index 48fd2c3..f7a0a1f 100644
--- a/l2tp_config_parse.y
+++ b/l2tp_config_parse.y
@@ -149,6 +149,7 @@ extern void yyfatal(const char *s);
 %token IPV6CP_MAX_TERMINATE_REQUESTS
 %token IPV6CP_RETRANSMIT_INTERVAL
 %token IPCP_ENABLE
+%token IPPARAM
 %token EOT
 %token SLASH
 %token BLCL
@@ -1203,6 +1204,18 @@ ppp_profile_statement
                        ppp_profile.flags2 |= 
L2TP_API_PPP_PROFILE_FLAG_IPCP_ENABLE;
                        ppp_profile.ipcp_enable = $3;
                }
+       |       IPPARAM EQUALS STRING
+               {
+                       ppp_profile.flags2 |= L2TP_API_PPP_PROFILE_FLAG_IPPARAM;
+                       OPTSTRING(ppp_profile.ipparam) = $3.buf;
+                       ppp_profile.ipparam.valid = 1;
+               }
+       |       IPPARAM EQUALS QUOTEDSTRING
+               {
+                       ppp_profile.flags2 |= L2TP_API_PPP_PROFILE_FLAG_IPPARAM;
+                       OPTSTRING(ppp_profile.ipparam) = $3.buf;
+                       ppp_profile.ipparam.valid = 1;
+               }
        ;
 
 tunnel_command
diff --git a/l2tp_config_token.l b/l2tp_config_token.l
index af5f53b..6fbfa7c 100644
--- a/l2tp_config_token.l
+++ b/l2tp_config_token.l
@@ -197,6 +197,7 @@ ipv6cp_max_config_naks                      { 
return(IPV6CP_MAX_CONFIG_NAKS); }
 ipv6cp_max_terminate_requests          { 
return(IPV6CP_MAX_TERMINATE_REQUESTS); }
 ipv6cp_retransmit_interval             { return(IPV6CP_RETRANSMIT_INTERVAL); }
 ipcp_enable                            { return(IPCP_ENABLE); }
+ipparam                                        { return(IPPARAM); }
 
 {ws}           { }
 {linecont}     { lineno++; }
diff --git a/l2tp_ppp.c b/l2tp_ppp.c
index 2bf6243..bd4492f 100644
--- a/l2tp_ppp.c
+++ b/l2tp_ppp.c
@@ -76,6 +76,7 @@ struct l2tp_ppp_profile {
        int                             auth_refuse_eap:1;
        int                             ipv6cp_enable:1;
        int                             ipcp_enable:1;
+       char                            *ipparam;
 };
 
 static struct l2tp_ppp_profile *l2tp_ppp_defaults;
@@ -265,6 +266,9 @@ static int 
l2tp_ppp_profile_modify(l2tp_api_ppp_profile_msg_data *msg, struct l2
        if (msg->flags2 & L2TP_API_PPP_PROFILE_FLAG_IPCP_ENABLE) {
                profile->ipcp_enable = msg->ipcp_enable;
        }
+       if (msg->flags2 & L2TP_API_PPP_PROFILE_FLAG_IPPARAM) {
+               L2TP_SET_OPTSTRING_VAR(profile, ipparam);
+       }
 
 out:
        return result;
@@ -375,6 +379,13 @@ bool_t 
l2tp_ppp_profile_create_1_svc(l2tp_api_ppp_profile_msg_data msg, int *res
        profile->ipv6cp_max_terminate_requests = 
l2tp_ppp_defaults->ipv6cp_max_terminate_requests;
        profile->ipv6cp_retransmit_interval = 
l2tp_ppp_defaults->ipv6cp_retransmit_interval;
        profile->ipcp_enable = l2tp_ppp_defaults->ipcp_enable;
+       if (l2tp_ppp_defaults->ipparam != NULL) {
+               profile->ipparam = strdup(l2tp_ppp_defaults->ipparam);
+               if (profile->ipparam == NULL) {
+                       *result = -ENOMEM;
+                       goto err;
+               }
+       }
 
        /* Override defaults by user-supplied params */
        *result = l2tp_ppp_profile_modify(&msg, profile);
@@ -460,6 +471,9 @@ bool_t l2tp_ppp_profile_delete_1_svc(char *name, int 
*result, struct svc_req *re
        if (profile->remote_name != NULL) {
                free(profile->remote_name);
        }
+       if (profile->ipparam != NULL) {
+               free(profile->ipparam);
+       }
        USL_POISON_MEMORY(profile, 0xe5, sizeof(*profile));
        free(profile);
        *result = 0;
@@ -614,6 +628,14 @@ int l2tp_ppp_profile_get(char *name, struct 
l2tp_api_ppp_profile_msg_data *resul
        result->ipv6cp_max_terminate_requests = 
profile->ipv6cp_max_terminate_requests;
        result->ipv6cp_retransmit_interval = 
profile->ipv6cp_retransmit_interval;
        result->ipcp_enable = profile->ipcp_enable;
+       if (profile->ipparam != NULL) {
+               OPTSTRING(result->ipparam) = strdup(profile->ipparam);
+               if (OPTSTRING(result->ipparam) == NULL) {
+                       result->result_code = -ENOMEM;
+                       goto out;
+               }
+               result->ipparam.valid = 1;
+       }
 
 out:
        L2TP_DEBUG(L2TP_API, "%s: flags=%x/%x result=%d", __func__, 
result->flags, result->flags2, result->result_code);
@@ -634,6 +656,9 @@ void l2tp_ppp_profile_msg_free(struct 
l2tp_api_ppp_profile_msg_data *msg)
        if (OPTSTRING_PTR(msg->remote_name) != NULL) {
                free(OPTSTRING(msg->remote_name));
        }
+       if (OPTSTRING_PTR(msg->ipparam) != NULL) {
+               free(OPTSTRING(msg->ipparam));
+       }
        if (msg->profile_name != NULL) {
                free(msg->profile_name);
        }
@@ -897,6 +922,12 @@ bool_t 
l2tp_ppp_profile_unset_1_svc(l2tp_api_ppp_profile_unset_msg_data msg, int
        if (msg.flags2 & L2TP_API_PPP_PROFILE_FLAG_IPCP_ENABLE) {
                profile->ipcp_enable = L2TP_API_PPP_PROFILE_DEFAULT_IPCP_ENABLE;
        }
+       if (msg.flags2 & L2TP_API_PPP_PROFILE_FLAG_IPPARAM) {
+               if (profile->ipparam != NULL) {
+                       free(profile->ipparam);
+               }
+               profile->ipparam = NULL;
+       }
 
        /* Clear all requested flags */
        profile->flags &= ~(msg.flags);
@@ -997,6 +1028,12 @@ void l2tp_ppp_init(void)
        l2tp_ppp_defaults->ipv6cp_max_terminate_requests = 
L2TP_API_PPP_PROFILE_DEFAULT_IPV6CP_MAX_TERMINATE_REQUESTS;
        l2tp_ppp_defaults->ipv6cp_retransmit_interval = 
L2TP_API_PPP_PROFILE_DEFAULT_IPV6CP_RETRANSMIT_INTERVAL;
        l2tp_ppp_defaults->ipcp_enable = 
L2TP_API_PPP_PROFILE_DEFAULT_IPCP_ENABLE;
+       if (strlen(L2TP_API_PPP_PROFILE_DEFAULT_IPPARAM) > 0) {
+               l2tp_ppp_defaults->ipparam = 
strdup(L2TP_API_PPP_PROFILE_DEFAULT_IPPARAM);
+               if (l2tp_ppp_defaults->ipparam == NULL) {
+                       goto nomem;
+               }
+       }
 
        USL_LIST_HEAD_INIT(&l2tp_ppp_defaults->list);
        usl_list_add(&l2tp_ppp_defaults->list, &l2tp_ppp_profile_list);
diff --git a/l2tp_rpc.x b/l2tp_rpc.x
index 4d6d0aa..fa65481 100644
--- a/l2tp_rpc.x
+++ b/l2tp_rpc.x
@@ -952,6 +952,7 @@ const L2TP_API_PPP_PROFILE_FLAG_IPV6CP_MAX_CONFIG_NAKS      
        = 2097152;
 const L2TP_API_PPP_PROFILE_FLAG_IPV6CP_MAX_TERMINATE_REQUESTS  = 4194304;
 const L2TP_API_PPP_PROFILE_FLAG_IPV6CP_RETRANSMIT_INTERVAL     = 8388608;
 const L2TP_API_PPP_PROFILE_FLAG_IPCP_ENABLE                    = 16777216;
+const L2TP_API_PPP_PROFILE_FLAG_IPPARAM                                = 
33554432;
 
 /* Default values for PPP profile attributes.
  * These are used if an explicit value is not provided by the user.
@@ -1005,6 +1006,7 @@ const L2TP_API_PPP_PROFILE_DEFAULT_IPV6CP_MAX_CONFIG_NAKS 
= 10;
 const L2TP_API_PPP_PROFILE_DEFAULT_IPV6CP_MAX_TERMINATE_REQUESTS= 3;
 const L2TP_API_PPP_PROFILE_DEFAULT_IPV6CP_RETRANSMIT_INTERVAL  = 3;
 const L2TP_API_PPP_PROFILE_DEFAULT_IPCP_ENABLE                 = 1;
+const L2TP_API_PPP_PROFILE_DEFAULT_IPPARAM                     = "";
 
 enum l2tp_api_ppp_sync_mode {
        L2TP_API_PPP_SYNCMODE_SYNC_ASYNC,
@@ -1069,6 +1071,7 @@ struct l2tp_api_ppp_profile_msg_data {
        int                             ipv6cp_max_terminate_requests;
        int                             ipv6cp_retransmit_interval;
        bool                            ipcp_enable;
+       optstring                       ipparam;
 };
 
 struct l2tp_api_ppp_profile_list_entry {
diff --git a/plugins/ppp_unix.c b/plugins/ppp_unix.c
index eae7ad3..08f191a 100644
--- a/plugins/ppp_unix.c
+++ b/plugins/ppp_unix.c
@@ -387,6 +387,12 @@ static int ppp_unix_params_to_argv(struct ppp_context 
*ppp, struct l2tp_api_ppp_
                argv[arg++] = "noip";
        }
 
+       /* ipparam extra parameter support */
+       if ((params->flags2 & L2TP_API_PPP_PROFILE_FLAG_IPPARAM) && 
(OPTSTRING_PTR(params->ipparam) != NULL)) {
+               argv[arg++] = "ipparam";
+               argv[arg++] = strdup(OPTSTRING(params->ipparam));
+       }
+
        /* Now handle each parameter from our translation table. Only
         * add the arg if the ppp profile indicates that it's been
         * set.
-- 
1.7.2.5


------------------------------------------------------------------------------
Try New Relic Now & We'll Send You this Cool Shirt
New Relic is the only SaaS-based application performance monitoring service 
that delivers powerful full stack analytics. Optimize and monitor your
browser, app, & servers with just a few lines of code. Try New Relic
and get this awesome Nerd Life shirt! http://p.sf.net/sfu/newrelic_d2d_apr
_______________________________________________
Openl2tp-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openl2tp-users

Reply via email to