Re: Is it possible to set MTU for a vpn connection



On Wed, 2009-09-02 at 10:56 -0400, Derek Atkins wrote:
> ritz <khadgaray gmail com> writes:
> 
> > Hello
> >
> >   I do not see any option to set MTU under NMSettingVPN. All I could
> > find was for ethernet, and wireless. Are there any plans to add this ?
> 
> The way I do this is manipulating the helper script to reset the MTU
> after the VPN comes up.  It's a PITA.
> 
> > reference:
> > http://live.gnome.org/NetworkManagerConfiguration
> > http://bugzilla.gnome.org/show_bug.cgi?id=584200
> 
> -derek


vpnc-console uses the the below to set MTU correctly

        if [ -n "$INTERNAL_IP4_MTU" ]; then
                MTU=$INTERNAL_IP4_MTU
        elif [ -n "$IPROUTE" ]; then
                DEV=$($IPROUTE route | grep ^default | sed 's/^.* dev
\([[:alnum:]-]\+\).*$/\1/')
                MTU=$(($($IPROUTE link show "$DEV" | grep mtu | sed
's/^.* mtu \([[:digit:]]\+\).*$/\1/') - 88))
        else
                MTU=1412
        fi



Which would roughly translate to the below. It seems I would have to use
libnl magic. Is there an alternate method ?

--- a/src/nm-vpnc-service-vpnc-helper.c
+++ b/src/nm-vpnc-service-vpnc-helper.c
@@ -368,10 +368,24 @@ main (int argc, char *argv[])
        if (val)
                g_hash_table_insert (config,
NM_VPN_PLUGIN_IP4_CONFIG_BANNER, val);
 
-       /* Set MTU to 1412 */
-       val = uint_to_gvalue (1412);
-       if (val)
-               g_hash_table_insert (config,
NM_VPN_PLUGIN_IP4_CONFIG_MTU, val);
+       /* MTU */
+       long int mtu ;
+       char *tmp = getenv ("INTERNAL_IP4_MTU");
+       if (tmp && strlen (tmp)) {
+               errno = 0;
+               mtu = strtol (tmp, NULL, 10);
+               if (errno || mtu < 0 || mtu > 20000) {
+                       nm_warning ("Ignoring invalid tunnel MTU '%s'",
tmp);
+                       mtu = 1412;
+               }
+       } else {
+               // netlink magic to obtain mtu for default interface
+               // and set vpnc-mtu = default-mtu - 88
+               // if the above fails, set mtu = 1412
+       }
+       val = uint_to_gvalue ((guint32) mtu);
+       g_hash_table_insert (config, NM_VPN_PLUGIN_IP4_CONFIG_MTU, val);
+
 
        /* Send the config info to nm-vpnc-service */
        send_ip4_config (connection, config);



-- 
Ritesh Khadgaray
Linux and Desktop
Ph: +919970164885
blog: http://khadgaray.blogspot.com
Eat Right, Exercise, Die Anyway.



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]