Skip to content

Commit

Permalink
config: rewrite kernel cmdline parser to be in sync with existing ker…
Browse files Browse the repository at this point in the history
…nel cmdline parameters

Signed-off-by: Philippe De Swert <philippe.deswert@jollamobile.com>
  • Loading branch information
philippedeswert committed May 24, 2013
1 parent 032043b commit 4bc50dd
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 10 deletions.
2 changes: 1 addition & 1 deletion configure.ac
@@ -1,4 +1,4 @@
AC_INIT([usb_moded], [0.61])
AC_INIT([usb_moded], [0.62])
AM_INIT_AUTOMAKE([-Wall -Werror foreign])

AM_CONFIG_HEADER([config.h])
Expand Down
7 changes: 7 additions & 0 deletions debian/changelog
@@ -1,3 +1,10 @@
usb-moded (0.62) unstable; urgency=low

* Kernel command line parameters are now in sync with regular kernel command parameters
* Save the udev path setting in config file merging so it does not get lost on upgrades

-- Philippe De Swert <philippe.deswert@jollamobile.com> Fri, 24 May 2013 17:20:54 +0300

usb-moded (0.61) unstable; urgency=low

* Add basic version of usb_moded_util to not having to remember dbus-send commands
Expand Down
12 changes: 10 additions & 2 deletions docs/usb_moded-doc.txt
Expand Up @@ -124,9 +124,17 @@ change and udev rules / network manager etc will not think it is a new device ea
This mac is stored using the default modprobe configuration and thus will be in /etc/modprobe.d/g_ether.conf
If this file exits usb_moded will assume there is a default mac set and will not do anything.

It is possible to set the configuration on the kernel command line also. Just add a valid keypair in the kernel command line.
It is possible to set the configuration on the kernel command line also. For this the regular ip setting from the kernel is
being re-used.

for example : ip=192.168.2.15 gateway=192.168.2.2 mode=developer_mode
The format followed is:
ip=<client-ip>:<server-ip>:<gw-ip>:<netmask>:<hostname>:<device>:<autoconf>

For more info see the kernel source: Documentation/filesystems/nfs/nfsroot.txt

for example : ip=192.168.3.100::192.168.3.1:255.255.255.0::usb0:on

NOTE: The device must be usb0! The autoconf value is ignored.

Functional overview
--------------------
Expand Down
33 changes: 26 additions & 7 deletions src/usb_moded-config.c
Expand Up @@ -236,6 +236,7 @@ static const char * get_kcmdline_string(const char *entry)
int len;
gint argc = 0;
gchar **argv = NULL;
gchar **arg_tokens = NULL, **network_tokens = NULL;
GError *optErr = NULL;
int i;

Expand All @@ -257,24 +258,42 @@ static const char * get_kcmdline_string(const char *entry)
cmdLine[len] = '\0';

/* we're looking for a piece of the kernel command line matching this:
ip=192.168.3.100:192.168.3.1::255.255.255.0::usb0:on */
ip=192.168.3.100::192.168.3.1:255.255.255.0::usb0:on */
if (!g_shell_parse_argv(cmdLine, &argc, &argv, &optErr))
{
g_error_free(optErr);
return(ret);
}

/* find the ip token */
for (i=0; i < argc; i++)
{
gchar ** arg_tokens;
arg_tokens = g_strsplit(argv[i], "=", 2);
if (!g_ascii_strcasecmp(arg_tokens[0], entry))
if (!g_ascii_strcasecmp(arg_tokens[0], "ip"))
{
log_debug("use '%s' for '%s' from kernel command line", arg_tokens[1], entry);
ret = g_strdup(arg_tokens[1]);
network_tokens = g_strsplit(arg_tokens[1], ":", 7);
/* check if it is for the usb */
if(!strcmp(network_tokens[5], "usb0"))
{
if(!strcmp(entry, NETWORK_IP_KEY))
{
ret = g_strdup(network_tokens[0]);
log_debug("Command line ip = %s\n", ret);
}
if(!strcmp(entry, NETWORK_GATEWAY_KEY))
{
/* gateway might be empty, so we do not want to return an empty string */
if(strlen(network_tokens[2]) > 2)
{
ret = g_strdup(network_tokens[2]);
log_debug("Command line gateway = %s\n", ret);
}
}
}
}
g_strfreev(arg_tokens);
}
g_strfreev(arg_tokens);
g_strfreev(network_tokens);

return(ret);
}
Expand Down Expand Up @@ -440,7 +459,7 @@ int conf_file_merge(void)
#ifdef UDEV
if(udev)
{
set_settings_option(UDEV_PATH_ENTRY, UDEV_PATH_KEY, udev);
set_config_setting(UDEV_PATH_ENTRY, UDEV_PATH_KEY, udev);
}
#endif /* UDEV */
}
Expand Down

0 comments on commit 4bc50dd

Please sign in to comment.