Commit df9976ae authored by Dan Williams's avatar Dan Williams
Browse files

2005-02-13 Dan Williams <dcbw@redhat.com>

	Patch from Dan Reed:  DHCP options D-BUS API
		Exposes the DHCP options that a device receives to clients over D-BUS.

	* configure.in
		- A few cleanups

	* dhcpcd/client.h
		- Correct names, option length, and types for DHCP options

	* dhcpcd/dhcpcd.[ch]
		- Clarify function names that access DHCP options & data

	* src/NetworkManagerDHCP.c
		- Use new DHCP data access functions

	* src/NetworkManagerDbus.c
		- Message handler for DHCP functions

	* src/nm-dbus-dhcp.[ch] (new)
		- DHCP dbus methods

	* test/nm-dhcp-opt-test.c
		- Test DHCP D-BUS API and return all present DHCP options


git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@444 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
parent 40e1dcb3
2005-02-13 Dan Williams <dcbw@redhat.com>
Patch from Dan Reed: DHCP options D-BUS API
Exposes the DHCP options that a device receives to clients over D-BUS.
* configure.in
- A few cleanups
* dhcpcd/client.h
- Correct names, option length, and types for DHCP options
* dhcpcd/dhcpcd.[ch]
- Clarify function names that access DHCP options & data
* src/NetworkManagerDHCP.c
- Use new DHCP data access functions
* src/NetworkManagerDbus.c
- Message handler for DHCP functions
* src/nm-dbus-dhcp.[ch] (new)
- DHCP dbus methods
* test/nm-dhcp-opt-test.c
- Test DHCP D-BUS API and return all present DHCP options
2005-02-12 Dan Williams <dcbw@redhat.com>
* test/Makefile.am
......
......@@ -31,6 +31,8 @@
#define NM_DBUS_INTERFACE "org.freedesktop.NetworkManager"
#define NM_DBUS_PATH_DEVICES "/org/freedesktop/NetworkManager/Devices"
#define NM_DBUS_INTERFACE_DEVICES "org.freedesktop.NetworkManager.Devices"
#define NM_DBUS_PATH_DHCP "/org/freedesktop/NetworkManager/DhcpOptions"
#define NM_DBUS_INTERFACE_DHCP "org.freedesktop.NetworkManager.DhcpOptions"
#define NMI_DBUS_SERVICE "org.freedesktop.NetworkManagerInfo"
#define NMI_DBUS_PATH "/org/freedesktop/NetworkManagerInfo"
......
......@@ -39,17 +39,7 @@ AC_DEFINE_UNQUOTED(GETTEXT_PACKAGE,"$GETTEXT_PACKAGE", [Gettext package])
ALL_LINGUAS="bs cs da de el en_CA es gu ja nb nl no pa pt_BR sk sq sv wa zh_CN"
AM_GLIB_GNU_GETTEXT
AC_ARG_WITH(distro,
[
--with-distro: Specify the Linux distribution to target with distro-specific
parts of NetworkManager
--with-distro=redhat
--with-distro=gentoo
--with-distro=debian
--with-distro=mandrake
--with-distro=slackware
],,)
AC_ARG_WITH(distro, AC_HELP_STRING([--with-distro=DISTRO], [Specify the Linux distribution to target: One of redhat, gentoo, debian, or slackware]))
if test "z$with_distro" = "z"; then
AC_CHECK_FILE(/etc/mandrake-release,with_distro="mandrake")
AC_CHECK_FILE(/etc/redhat-release,with_distro="redhat")
......@@ -61,13 +51,13 @@ fi
with_distro=`echo ${with_distro} | tr '[[:upper:]]' '[[:lower:]]' `
if test "z$with_distro" = "z"; then
echo "Linux distribution autodetection failed, you must specify the distribution to target using --with-distro=<distro>"
echo "Linux distribution autodetection failed, you must specify the distribution to target using --with-distro=DISTRO"
exit 1
else
case $with_distro in
redhat|gentoo|debian|slackware) ;;
*)
echo "Your distribution(${with_distro}) is not yet supported! (patches welcome)"
echo "Your distribution (${with_distro}) is not yet supported! (patches welcome)"
exit 1
;;
esac
......@@ -148,7 +138,7 @@ PKG_CHECK_MODULES(GNOME_KEYRING, gnome-keyring-1)
AC_SUBST(GNOME_KEYRING_CFLAGS)
AC_SUBST(GNOME_KEYRING_LIBS)
AC_ARG_WITH(gcrypt, [--with-gcrypt Use gcrypt library], ac_gcrypt=$withval, ac_gcrypt=auto)
AC_ARG_WITH(gcrypt, AC_HELP_STRING([--with-gcrypt], [Use gcrypt library]), ac_gcrypt=$withval, ac_gcrypt=auto)
if test x"$ac_gcrypt" != xno; then
AC_PATH_PROG(LIBGCRYPT_CONFIG, libgcrypt-config, no)
else
......@@ -175,11 +165,10 @@ AC_SUBST(PANEL_APPLET_CFLAGS)
AC_SUBST(PANEL_APPLET_LIBS)
PKG_CHECK_MODULES(LIBGNOMEUI, libgnomeui-2.0)
AC_SUBST(LIBGNOMEUI_CFLAFS)
AC_SUBST(LIBGNOMEUI_CFLAGS) # is this even needed? it was typed incorrectly before
AC_SUBST(LIBGNOMEUI_LIBS)
# taken from hal
AC_ARG_WITH(dbus-sys, [ --with-dbus-sys=<dir> where D-BUS system.d directory is])
AC_ARG_WITH(dbus-sys, AC_HELP_STRING([--with-dbus-sys=DIR], [where D-BUS system.d directory is]))
if ! test -z "$with_dbus_sys" ; then
DBUS_SYS_DIR="$with_dbus_sys"
......@@ -189,9 +178,9 @@ fi
AC_SUBST(DBUS_SYS_DIR)
AC_DEFINE_UNQUOTED(DBUS_SYSTEMD_DIR, "$DBUS_SYS_DIR", [Where system.d dir for DBUS is])
AC_ARG_WITH(named, AC_HELP_STRING([--with-named=<path>], [path to the named binary]))
AC_ARG_WITH(named_dir, AC_HELP_STRING([--with-named-dir=<path>], [path to the named data directory]))
AC_ARG_WITH(named_user, AC_HELP_STRING([--with-named-user=username], [named username]))
AC_ARG_WITH(named, AC_HELP_STRING([--with-named=PATH], [path to the named binary]))
AC_ARG_WITH(named_dir, AC_HELP_STRING([--with-named-dir=PATH], [path to the named data directory]))
AC_ARG_WITH(named_user, AC_HELP_STRING([--with-named-user=USERNAME], [named username]))
if test "x${with_named}" = x; then
AC_DEFINE(NM_NO_NAMED,,[Define if you want to disable named support])
fi
......@@ -199,7 +188,7 @@ AC_DEFINE_UNQUOTED(NM_NAMED_BINARY_PATH, "$with_named", [Define to path of named
AC_DEFINE_UNQUOTED(NM_NAMED_DATA_DIR, "$with_named_dir", [Define to path of named data directory])
AC_DEFINE_UNQUOTED(NM_NAMED_USER, "$with_named_user", [Define to named username])
AC_ARG_ENABLE(notification-icon, [ --enable-notification-icon builds the wireless applet as a notification icon], enable_notification_icon=$enableval, enable_notification_icon=yes)
AC_ARG_ENABLE(notification-icon, AC_HELP_STRING([--enable-notification-icon], [builds the wireless applet as a notification icon]), enable_notification_icon=$enableval, enable_notification_icon=yes)
AM_CONDITIONAL(BUILD_NOTIFICATION_ICON, test x$enable_notification_icon = xyes)
if test x$enable_notification_icon == xyes ; then
......@@ -240,7 +229,7 @@ prefix=$old_prefix
exec_prefix=$old_exec_prefix
AC_ARG_ENABLE(more-warnings,
[ --enable-more-warnings Maximum compiler warnings],
AC_HELP_STRING([--enable-more-warnings], [Maximum compiler warnings]),
set_more_warnings="$enableval",[
if test -d "$srcdir/{arch}" || test -d "$srcdir/CVS"; then
set_more_warnings=yes
......@@ -295,4 +284,4 @@ libnm_glib/libnm_glib.pc
echo
echo Distribution targeting: ${with_distro}
echo 'if this is not correct, please specifiy your distro with --with-distro=<distro>'
echo 'if this is not correct, please specifiy your distro with --with-distro=DISTRO'
......@@ -83,9 +83,9 @@ typedef struct dhcpMessage
typedef struct dhcpOptions
{
u_char num;
u_char len[256];
void *val[256];
u_char num;
} __attribute__((packed)) dhcpOptions;
struct packed_ether_header
......@@ -132,75 +132,145 @@ typedef struct dhcp_interface
typedef struct dhcp_option_table
{
const int option;
const char *name;
const int len;
const char *name;
const int len_hint;
dhcp_option_type type;
} dhcp_option_table;
static dhcp_option_table dhcp_opt_table[] =
{
{ padOption, "padOption", 1 },
{ subnetMask, "subnetMask", 4 },
{ timerOffset, "timerOffset", -1 },
{ routersOnSubnet, "routersOnSubnet", 4 },
{ timeServer, "timeServer", 4 },
{ nameServer, "nameServer", 4 },
{ dns, "dns", 4 },
{ logServer, "logServer", 4 },
{ cookieServer, "cookieServer", 4 },
{ lprServer, "lprServer", 4 },
{ impressServer, "impressServer", 4 },
{ resourceLocationServer,"resourceLocationServer",4 },
{ hostName, "hostName", -1 },
{ bootFileSize, "bootFileSize", 4 },
{ meritDumpFile, "meritDumpFile", 4 },
{ domainName, "domainName", -1 },
{ swapServer, "swapServer", 4 },
{ rootPath, "rootPath", -1 },
{ extentionsPath, "extentionsPath", -1 },
{ IPforwarding, "IPforwarding", -1 },
{ nonLocalSourceRouting, "nonLocalSourceRouting", -1 },
{ policyFilter, "policyFilter", -1 },
{ maxDgramReasmSize, "maxDgramReasmSize", -1 },
{ defaultIPTTL, "defaultIPTTL", -1 },
{ pathMTUagingTimeout, "pathMTUagingTimeout", -1 },
{ pathMTUplateauTable, "pathMTUplateauTable", -1 },
{ ifMTU, "ifMTU", -1 },
{ allSubnetsLocal, "allSubnetsLocal", -1 },
{ broadcastAddr, "broadcastAddr", 4 },
{ performMaskDiscovery, "performMaskDiscovery", -1 },
{ routerSolicitationAddr,"routerSolicitationAddr",-1 },
{ staticRoute, "staticRoute", 4 },
{ trailerEncapsulation, "trailerEncapsulation", -1 },
{ arpCacheTimeout, "arpCacheTimeout", -1 },
{ ethernetEncapsulation, "ethernetEncapsulation", -1 },
{ tcpDefaultTTL, "tcpDefaultTTL", -1 },
{ tcpKeepaliveInterval, "tcpKeepaliveInterval", -1 },
{ tcpKeepaliveGarbage, "tcpKeepaliveGarbage", -1 },
{ nisDomainName, "nisDomainName", -1 },
{ nisServers, "nisServers", 4 },
{ ntpServers, "ntpServers", 4 },
{ vendorSpecificInfo, "vendorSpecificInfo", -1 },
{ netBIOSnameServer, "netBIOSnameServer", -1 },
{ netBIOSdgramDistServer,"netBIOSdgramDistServer",-1 },
{ netBIOSnodeType, "netBIOSnodeType", -1 },
{ netBIOSscope, "netBIOSscope", -1 },
{ xFontServer, "xFontServer", -1 },
{ xDisplayManager, "xDisplayManager", -1 },
{ dhcpRequestedIPaddr, "dhcpRequestedIPaddr", 4 },
{ dhcpIPaddrLeaseTime, "dhcpIPaddrLeaseTime", 4 },
{ dhcpOptionOverload, "dhcpOptionOverload", -1 },
{ dhcpMessageType, "dhcpMessageType", -1 },
{ dhcpServerIdentifier, "dhcpServerIdentifier", -1 },
{ dhcpParamRequest, "dhcpParamRequest", -1 },
{ dhcpMsg, "dhcpMsg", -1 },
{ dhcpMaxMsgSize, "dhcpMaxMsgSize", -1 },
{ dhcpT1value, "dhcpT1value", 4 },
{ dhcpT2value, "dhcpT2value", 4 },
{ dhcpClassIdentifier, "dhcpClassIdentifier", -1 },
{ dhcpClientIdentifier, "dhcpClientIdentifier", -1 },
{ -1, NULL, -1 }
/* Names come from http://www.iana.org/assignments/bootp-dhcp-parameters, not to be changed */
/* 0 */ { "Pad", 0, DHCP_OPT_INVALID },
/* 1 */ { "Subnet Mask", 4, DHCP_OPT_ADDRESS },
/* 2 */ { "Time Offset", 4, DHCP_OPT_TIME },
/* 3 */ { "Router", 4, DHCP_OPT_ADDRESS },
/* 4 */ { "Time Server", 4, DHCP_OPT_ADDRESS },
/* 5 */ { "Name Server", 4, DHCP_OPT_ADDRESS },
/* 6 */ { "Domain Server", 4, DHCP_OPT_ADDRESS },
/* 7 */ { "Log Server", 4, DHCP_OPT_ADDRESS },
/* 8 */ { "Quotes Server", 4, DHCP_OPT_ADDRESS },
/* 9 */ { "LPR Server", 4, DHCP_OPT_ADDRESS },
/* 10 */ { "Impress Server", 4, DHCP_OPT_ADDRESS },
/* 11 */ { "RLP Server", 4, DHCP_OPT_ADDRESS },
/* 12 */ { "Hostname", 1, DHCP_OPT_STRING },
/* 13 */ { "Boot File Size", 2, DHCP_OPT_COUNT },
/* 14 */ { "Merit Dump File", 1, DHCP_OPT_STRING },
/* 15 */ { "Domain Name", 1, DHCP_OPT_STRING },
/* 16 */ { "Swap Server", 1, DHCP_OPT_ADDRESS },
/* 17 */ { "Root Path", 1, DHCP_OPT_STRING },
/* 18 */ { "Extension Path", 1, DHCP_OPT_STRING },
/* 19 */ { "Forward On/Off", 1, DHCP_OPT_TOGGLE },
/* 20 */ { "SrcRte On/Off", 1, DHCP_OPT_TOGGLE },
/* 21 */ { "Policy Filter", 1, DHCP_OPT_BLOB },
/* 22 */ { "Max DG Assembly", 2, DHCP_OPT_COUNT },
/* 23 */ { "Default IP TTL", 1, DHCP_OPT_COUNT },
/* 24 */ { "MTU Timeout", 4, DHCP_OPT_TIME },
/* 25 */ { "MTU Plateau", 1, DHCP_OPT_BLOB },
/* 26 */ { "MTU Interface", 2, DHCP_OPT_COUNT },
/* 27 */ { "MTU Subnet", 1, DHCP_OPT_TOGGLE },
/* 28 */ { "Broadcast Address", 4, DHCP_OPT_ADDRESS },
/* 29 */ { "Mask Discovery", 1, DHCP_OPT_TOGGLE },
/* 30 */ { "Mask Supplier", 1, DHCP_OPT_TOGGLE },
/* 31 */ { "Router Discovery", 1, DHCP_OPT_TOGGLE },
/* 32 */ { "Router Request", 4, DHCP_OPT_ADDRESS },
/* 33 */ { "Static Route", 1, DHCP_OPT_BLOB },
/* 34 */ { "Trailers", 1, DHCP_OPT_TOGGLE },
/* 35 */ { "ARP Timeout", 4, DHCP_OPT_TIME },
/* 36 */ { "Ethernet", 1, DHCP_OPT_BLOB },
/* 37 */ { "Default TCP TTL", 1, DHCP_OPT_COUNT},
/* 38 */ { "Keepalive Time", 4, DHCP_OPT_TIME },
/* 39 */ { "Keepalive Data", 1, DHCP_OPT_BLOB },
/* 40 */ { "NIS Domain", 1, DHCP_OPT_STRING },
/* 41 */ { "NIS Servers", 4, DHCP_OPT_ADDRESS },
/* 42 */ { "NTP Servers", 4, DHCP_OPT_ADDRESS },
/* 43 */ { "Vendor Specific", 1, DHCP_OPT_BLOB },
/* 44 */ { "NETBIOS Name Srv", 4, DHCP_OPT_ADDRESS },
/* 45 */ { "NETBIOS Dist Srv", 4, DHCP_OPT_ADDRESS },
/* 46 */ { "NETBIOS Node Type", 1, DHCP_OPT_NUMBER },
/* 47 */ { "NETBIOS Scope", 1, DHCP_OPT_NUMBER },
/* 48 */ { "X Window Font", 4, DHCP_OPT_ADDRESS },
/* 49 */ { "X Window Manager", 4, DHCP_OPT_ADDRESS },
/* 50 */ { "Address Request", 4, DHCP_OPT_ADDRESS },
/* 51 */ { "Address Time", 4, DHCP_OPT_TIME },
/* 52 */ { "Overload", 1, DHCP_OPT_BLOB },
/* 53 */ { "DHCP Msg Type", 1, DHCP_OPT_NUMBER },
/* 54 */ { "DHCP Server Id", 4, DHCP_OPT_ADDRESS },
/* 55 */ { "Parameter List", 1, DHCP_OPT_BLOB },
/* 56 */ { "DHCP Message", 1, DHCP_OPT_BLOB },
/* 57 */ { "DHCP Max Msg Size", 2, DHCP_OPT_COUNT },
/* 58 */ { "Renewal Time", 4, DHCP_OPT_TIME },
/* 59 */ { "Rebinding Time", 4, DHCP_OPT_TIME },
/* 60 */ { "Class Id", 1, DHCP_OPT_BLOB },
/* 61 */ { "Client Id", 1, DHCP_OPT_BLOB },
/* 62 */ { "NetWare/IP Domain", 1, DHCP_OPT_STRING },
/* 63 */ { "NetWare/IP Option", 1, DHCP_OPT_BLOB },
/* 64 */ { "NIS-Domain-Name", 1, DHCP_OPT_STRING },
/* 65 */ { "NIS-Server-Addr", 4, DHCP_OPT_ADDRESS },
/* 66 */ { "Server-Name", 1, DHCP_OPT_STRING },
/* 67 */ { "Bootfile-Name", 1, DHCP_OPT_STRING },
/* 68 */ { "Home-Agent-Addrs", 4, DHCP_OPT_ADDRESS },
/* 69 */ { "SMTP-Server", 4, DHCP_OPT_ADDRESS },
/* 70 */ { "POP3-Server", 4, DHCP_OPT_ADDRESS },
/* 71 */ { "NNTP-Server", 4, DHCP_OPT_ADDRESS },
/* 72 */ { "WWW-Server", 4, DHCP_OPT_ADDRESS },
/* 73 */ { "Finger-Server", 4, DHCP_OPT_ADDRESS },
/* 74 */ { "IRC-Server", 4, DHCP_OPT_ADDRESS },
/* 75 */ { "StreetTalk-Server", 4, DHCP_OPT_ADDRESS },
/* 76 */ { "STDA-Server", 4, DHCP_OPT_ADDRESS },
/* 77 */ { "User-Class", 1, DHCP_OPT_BLOB },
/* 78 */ { "Directory Agent", 1, DHCP_OPT_BLOB },
/* 79 */ { "Service Scope", 1, DHCP_OPT_BLOB },
/* 80 */ { "Rapid Commit", 0, DHCP_OPT_BLOB },
/* 81 */ { "Client FQDN", 1, DHCP_OPT_STRING },
/* 82 */ { "Relay Agent Information", 1, DHCP_OPT_BLOB },
/* 83 */ { "iSNS", 1, DHCP_OPT_BLOB },
/* 84 */ { NULL, 0, DHCP_OPT_INVALID },
/* 85 */ { "NDS Servers", 4, DHCP_OPT_ADDRESS },
/* 86 */ { "NDS Tree Name", 1, DHCP_OPT_BLOB },
/* 87 */ { "NDS Context", 1, DHCP_OPT_BLOB },
/* 88 */ { NULL, 0, DHCP_OPT_INVALID },
/* 89 */ { NULL, 0, DHCP_OPT_INVALID },
/* 90 */ { "Authentication", 1, DHCP_OPT_BLOB },
/* 91 */ { NULL, 0, DHCP_OPT_INVALID },
/* 92 */ { NULL, 0, DHCP_OPT_INVALID },
/* 93 */ { "Client System", 1, DHCP_OPT_BLOB },
/* 94 */ { "Client NDI", 1, DHCP_OPT_BLOB },
/* 95 */ { "LDAP", 1, DHCP_OPT_BLOB },
/* 96 */ { NULL, 0, DHCP_OPT_INVALID },
/* 97 */ { "UUID/GUID", 1, DHCP_OPT_BLOB },
/* 98 */ { "User-Auth", 1, DHCP_OPT_BLOB },
/* 99 */ { NULL, 0, DHCP_OPT_INVALID },
/* 100 */ { NULL, 0, DHCP_OPT_INVALID },
/* 101 */ { NULL, 0, DHCP_OPT_INVALID },
/* 102 */ { NULL, 0, DHCP_OPT_INVALID },
/* 103 */ { NULL, 0, DHCP_OPT_INVALID },
/* 104 */ { NULL, 0, DHCP_OPT_INVALID },
/* 105 */ { NULL, 0, DHCP_OPT_INVALID },
/* 106 */ { NULL, 0, DHCP_OPT_INVALID },
/* 107 */ { NULL, 0, DHCP_OPT_INVALID },
/* 108 */ { NULL, 0, DHCP_OPT_INVALID },
/* 109 */ { NULL, 0, DHCP_OPT_INVALID },
/* 110 */ { NULL, 0, DHCP_OPT_INVALID },
/* 111 */ { NULL, 0, DHCP_OPT_INVALID },
/* 112 */ { "Netinfo Address", 1, DHCP_OPT_BLOB },
/* 113 */ { "Netinfo Tag", 1, DHCP_OPT_BLOB },
/* 114 */ { "URL", 1, DHCP_OPT_STRING },
/* 115 */ { NULL, 1, DHCP_OPT_BLOB },
/* 116 */ { "Auto-Config", 1, DHCP_OPT_BLOB },
/* 117 */ { "Name Service Search", 1, DHCP_OPT_BLOB },
/* 118 */ { "Subnet Selection Option", 4, DHCP_OPT_BLOB },
/* 119 */ { "Domain Search", 1, DHCP_OPT_STRING },
/* 120 */ { "SIP Servers DHCP Option", 1, DHCP_OPT_BLOB },
/* 121 */ { "Classless Static Route Option", 1, DHCP_OPT_BLOB },
/* 122 */ { "CCC", 1, DHCP_OPT_BLOB },
/* 123 */ { "GeoConf Option", 16, DHCP_OPT_BLOB },
/* 124 */ { "V-I Vendor Class", 1, DHCP_OPT_BLOB },
/* 125 */ { "V-I Vendor-Specific Information", 1, DHCP_OPT_BLOB },
/* 126 */ { NULL, 0, DHCP_OPT_INVALID },
/* 127 */ { NULL, 0, DHCP_OPT_INVALID },
};
static const int dhcp_opt_table_len = sizeof(dhcp_opt_table)/sizeof(*dhcp_opt_table);
typedef udpipMessage *(*dhcp_msg_build_proc)(dhcp_interface *, int *msg_len);
......
......@@ -260,7 +260,7 @@ void dhcp_interface_cease (dhcp_interface *iface)
}
/*****************************************************************************/
int dhcp_interface_dhcp_field_exists (dhcp_interface *iface, int val)
int dhcp_interface_option_present (dhcp_interface *iface, int val)
{
if (!iface) return 0;
......@@ -268,7 +268,7 @@ int dhcp_interface_dhcp_field_exists (dhcp_interface *iface, int val)
}
/*****************************************************************************/
void *dhcp_interface_get_dhcp_field (dhcp_interface *iface, int val)
void *dhcp_interface_option_payload (dhcp_interface *iface, int val)
{
if (!iface) return 0;
......@@ -276,7 +276,7 @@ void *dhcp_interface_get_dhcp_field (dhcp_interface *iface, int val)
}
/*****************************************************************************/
int dhcp_interface_get_dhcp_field_len (dhcp_interface *iface, int val)
int dhcp_interface_option_len (dhcp_interface *iface, int val)
{
if (!iface) return 0;
......@@ -284,11 +284,61 @@ int dhcp_interface_get_dhcp_field_len (dhcp_interface *iface, int val)
}
/*****************************************************************************/
int dhcp_individual_value_len (int val)
int dhcp_option_record_len (int val)
{
if (val <= dhcpClientIdentifier)
return (dhcp_opt_table[val].len);
if ((val >= 0) && (val < dhcp_opt_table_len))
return (dhcp_opt_table[val].len_hint);
else
return -1;
}
/*****************************************************************************/
const char *dhcp_option_name (int val)
{
if ((val >= 0) && (val < dhcp_opt_table_len))
return (dhcp_opt_table[val].name);
else
return NULL;
}
/*****************************************************************************/
dhcp_option_type dhcp_option_record_type (int val)
{
if ((val >= 0) && (val < dhcp_opt_table_len))
return (dhcp_opt_table[val].type);
else
return -1;
}
/* case-insensitive alpha/num string comparison; skips over white space and punctuation */
static int dhcp_strcmp (const unsigned char *s1, const unsigned char *s2)
{
while (!isalnum(*s1) && (*s1 != 0))
s1++;
while (!isalnum(*s2) && (*s2 != 0))
s2++;
while (*s1 != 0) {
if (tolower(*s1) != tolower(*s2))
return ((tolower(*s1) < tolower(*s2))?-1:1);
s1++;
s2++;
while (!isalnum(*s1) && (*s1 != 0))
s1++;
while (!isalnum(*s2) && (*s2 != 0))
s2++;
}
if (*s2 != 0)
return ((tolower(*s1) < tolower(*s2))?-1:1);
return (0);
}
/*****************************************************************************/
int dhcp_option_id_by_name (const char *name)
{
int i;
for (i = 0; i < dhcp_opt_table_len; i++)
if ((dhcp_opt_table[i].name != NULL) && (dhcp_strcmp (name, dhcp_opt_table[i].name) == 0))
return (i);
return (-1);
}
......@@ -99,6 +99,18 @@ enum
endOption = 255
};
typedef enum dhcp_option_type
{
DHCP_OPT_INVALID,
DHCP_OPT_ADDRESS,
DHCP_OPT_TIME,
DHCP_OPT_STRING,
DHCP_OPT_COUNT,
DHCP_OPT_TOGGLE,
DHCP_OPT_BLOB,
DHCP_OPT_NUMBER,
} dhcp_option_type;
/* Return codes */
#define RET_DHCP_ERROR 0
#define RET_DHCP_ADDRESS_IN_USE 1
......@@ -122,13 +134,16 @@ typedef struct dhcp_client_options
int window;
} dhcp_client_options;
struct dhcp_interface *dhcp_interface_init (const char *if_name, dhcp_client_options *in_opts);
void dhcp_interface_free (struct dhcp_interface *iface);
void dhcp_interface_cease (struct dhcp_interface *iface);
struct dhcp_interface *dhcp_interface_init (const char *if_name, dhcp_client_options *in_opts);
void dhcp_interface_free (struct dhcp_interface *iface);
void dhcp_interface_cease (struct dhcp_interface *iface);
int dhcp_interface_dhcp_field_exists (struct dhcp_interface *iface, int val);
int dhcp_interface_get_dhcp_field_len (struct dhcp_interface *iface, int val);
void *dhcp_interface_get_dhcp_field (struct dhcp_interface *iface, int val);
int dhcp_individual_value_len (int val);
int dhcp_interface_option_present (struct dhcp_interface *iface, int val);
int dhcp_interface_option_len (struct dhcp_interface *iface, int val);
void *dhcp_interface_option_payload (struct dhcp_interface *iface, int val);
int dhcp_option_record_len (int val);
dhcp_option_type dhcp_option_record_type (int val);
int dhcp_option_id_by_name (const char *name);
const char * dhcp_option_name (int val);
#endif
......@@ -13,12 +13,16 @@ NetworkManager_SOURCES = \
NetworkManagerDbus.h \
NetworkManagerDbusUtils.c \
NetworkManagerDbusUtils.h \
nm-dbus-nm.h \
nm-dbus-nm.c \
nm-dbus-device.h \
nm-dbus-nm.h \
nm-dbus-device.c \
nm-dbus-net.h \
nm-dbus-device.h \
nm-dbus-net.c \
nm-dbus-net.h \
nm-dbus-dhcp.c \
nm-dbus-dhcp.h \
nm-dbus-nmi.c \
nm-dbus-nmi.h \
NetworkManagerDHCP.c \
NetworkManagerDHCP.h \
NetworkManagerDevice.c \
......
......@@ -127,31 +127,31 @@ static void nm_device_dhcp_configure (NMDevice *dev)
/* Replace basic info */
nm_system_device_set_ip4_address (dev, dev->dhcp_iface->ciaddr);
if (dhcp_interface_dhcp_field_exists (dev->dhcp_iface, subnetMask))
if (dhcp_interface_option_present (dev->dhcp_iface, subnetMask))
{
memcpy (&temp, dhcp_interface_get_dhcp_field (dev->dhcp_iface, subnetMask), dhcp_individual_value_len (subnetMask));
memcpy (&temp, dhcp_interface_option_payload (dev->dhcp_iface, subnetMask), dhcp_option_record_len (subnetMask));
nm_system_device_set_ip4_netmask (dev, temp);
}
if (dhcp_interface_dhcp_field_exists (dev->dhcp_iface, broadcastAddr))
if (dhcp_interface_option_present (dev->dhcp_iface, broadcastAddr))
{
memcpy (&temp, dhcp_interface_get_dhcp_field (dev->dhcp_iface, broadcastAddr), dhcp_individual_value_len (broadcastAddr));
memcpy (&temp, dhcp_interface_option_payload (dev->dhcp_iface, broadcastAddr), dhcp_option_record_len (broadcastAddr));
nm_system_device_set_ip4_broadcast (dev, temp);
}
/* Default route */
if (dhcp_interface_dhcp_field_exists (dev->dhcp_iface, routersOnSubnet))
if (dhcp_interface_option_present (dev->dhcp_iface, routersOnSubnet))
{
memcpy (&temp, dhcp_interface_get_dhcp_field (dev->dhcp_iface, routersOnSubnet), dhcp_individual_value_len (routersOnSubnet));
memcpy (&temp, dhcp_interface_option_payload (dev->dhcp_iface, routersOnSubnet), dhcp_option_record_len (routersOnSubnet));
nm_system_device_set_ip4_default_route (dev, temp);
}
/* Update /etc/resolv.conf */
if (dhcp_interface_dhcp_field_exists (dev->dhcp_iface, dns))
set_nameservers (dev, dhcp_interface_get_dhcp_field (dev->dhcp_iface, dns), dhcp_interface_get_dhcp_field_len (dev->dhcp_iface, dns));
if (dhcp_interface_option_present (dev->dhcp_iface, dns))
set_nameservers (dev, dhcp_interface_option_payload (dev->dhcp_iface, dns), dhcp_interface_option_len (dev->dhcp_iface, dns));
if (dhcp_interface_dhcp_field_exists (dev->dhcp_iface, domainName))
set_domain_search (dev, dhcp_interface_get_dhcp_field (dev->dhcp_iface, domainName));
if (dhcp_interface_option_present (dev->dhcp_iface, domainName))
set_domain_search (dev, dhcp_interface_option_payload (dev->dhcp_iface, domainName));
}
......@@ -263,14 +263,14 @@ gboolean nm_device_dhcp_setup_timeouts (NMDevice *dev)
g_return_val_if_fail (dev != NULL, FALSE);
if (dhcp_interface_dhcp_field_exists (dev->dhcp_iface, dhcpT1value))
if (dhcp_interface_option_present (dev->dhcp_iface, dhcpT1value))
{
memcpy (&t1, dhcp_interface_get_dhcp_field (dev->dhcp_iface, dhcpT1value), sizeof (int));
memcpy (&t1, dhcp_interface_option_payload (dev->dhcp_iface, dhcpT1value), sizeof (int));
t1 = ntohl (t1);
}
if (dhcp_interface_dhcp_field_exists (dev->dhcp_iface, dhcpT2value))
if (dhcp_interface_option_present (dev->dhcp_iface, dhcpT2value))
{
memcpy (&t2, dhcp_interface_get_dhcp_field (dev->dhcp_iface, dhcpT2value), sizeof (int));
memcpy (&t2, dhcp_interface_option_payload (dev->dhcp_iface, dhcpT2value), sizeof (int));
t2 = ntohl (t2);
}
if (!t1 || !t2)
......
......@@ -38,6 +38,7 @@
#include "nm-dbus-nm.h"
#include "nm-dbus-device.h"
#include "nm-dbus-net.h"
#include "nm-dbus-dhcp.h"
/*
......@@ -979,6 +980,41 @@ static DBusHandlerResult nm_dbus_devices_message_handler (DBusConnection *connec
}
/*
* nm_dbus_dhcp_message_handler
*
* Dispatch messages against our NetworkManager DHCP object
*
* All calls are in the form /NM_DBUS_PATH_DHCP->METHOD (STRING attribute)
* For example, /org/freedesktop/NetworkManager/DhcpOptions->getType ("Name Server")
*
*/
static DBusHandlerResult nm_dbus_dhcp_message_handler (DBusConnection *connection, DBusMessage *message, void *user_data)
{
NMData *data = (NMData *)user_data;
gboolean handled = TRUE;
DBusMessage *reply = NULL;
NMDbusCBData cb_data;
g_return_val_if_fail (data != NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
g_return_val_if_fail (data->dhcp_methods != NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
g_return_val_if_fail (connection != NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
g_return_val_if_fail (message != NULL, DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
cb_data.data = data;
cb_data.dev = NULL;
cb_data.opt_id = -1;
handled = nm_dbus_method_dispatch (data->dhcp_methods, connection, message, &cb_data, &reply);
if (reply)