summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2003-10-13 17:40:45 +0000
committerLennart Poettering <lennart@poettering.net>2003-10-13 17:40:45 +0000
commitf350c50a1a059489666ce31f33153771626182ea (patch)
tree23487b9aefaaf0ad95e4f45b89205f76812463ec
parent866bc8fd59b7134b800faad565ed00b2e3b09b36 (diff)
Large commit
git-svn-id: file:///home/lennart/svn/public/aeswepd/trunk@20 022f378f-78c4-0310-b860-d162c87e6274
-rw-r--r--Makefile.am2
-rw-r--r--configure.ac4
-rw-r--r--doc/Makefile.am8
-rw-r--r--doc/NEWDRIVERS18
-rw-r--r--man/Makefile.am40
-rw-r--r--man/aeswepd.8.xml.in175
-rw-r--r--man/man.css30
-rw-r--r--man/man.xsl120
-rw-r--r--src/Makefile.am2
-rw-r--r--src/aeswepd.c61
-rw-r--r--src/interface.c44
-rw-r--r--src/interface.h1
-rw-r--r--src/iwkey.c16
-rw-r--r--src/iwkey.h7
-rw-r--r--src/keyapi.c29
-rw-r--r--src/keyapi.h37
-rw-r--r--src/netlink.h177
-rw-r--r--src/rtnetlink.h631
-rw-r--r--src/util.c79
-rw-r--r--src/util.h10
-rw-r--r--src/wireless.h4
21 files changed, 513 insertions, 982 deletions
diff --git a/Makefile.am b/Makefile.am
index 3334a07..107f524 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -17,7 +17,7 @@
# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
EXTRA_DIST=bootstrap.sh README LICENSE
-SUBDIRS=src doc #man
+SUBDIRS=src doc man
MAINTAINERCLEANFILES = README
noinst_DATA = README
diff --git a/configure.ac b/configure.ac
index 40aed44..e890da7 100644
--- a/configure.ac
+++ b/configure.ac
@@ -20,7 +20,7 @@
# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
AC_PREREQ(2.57)
-AC_INIT([aeswepd], [0.2], [mznrfjrcq (at) 0pointer (dot) de])
+AC_INIT([aeswepd], [0.3], [mznrfjrcq (at) 0pointer (dot) de])
AC_CONFIG_SRCDIR([src/aeswepd.c])
AC_CONFIG_HEADERS([config.h])
AM_INIT_AUTOMAKE([foreign -Wall])
@@ -101,5 +101,5 @@ fi
AM_CONDITIONAL([USE_XMLTOMAN], [test "x$xmltoman" = xyes])
-AC_CONFIG_FILES([src/Makefile Makefile doc/Makefile]) # man/Makefile doc/Makefile doc/README.html])
+AC_CONFIG_FILES([src/Makefile Makefile doc/Makefile man/Makefile]) # doc/README.html])
AC_OUTPUT
diff --git a/doc/Makefile.am b/doc/Makefile.am
index d36fe90..e9e863e 100644
--- a/doc/Makefile.am
+++ b/doc/Makefile.am
@@ -1,19 +1,19 @@
# $Id$
-# This file is part of waproamd.
+# This file is part of aeswepd.
#
-# waproamd is free software; you can redistribute it and/or modify it
+# aeswepd 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.
#
-# waproamd is distributed in the hope that it will be useful, but
+# aeswepd 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 waproamd; if not, write to the Free Software Foundation,
+# along with aeswepd; if not, write to the Free Software Foundation,
# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
EXTRA_DIST=README
diff --git a/doc/NEWDRIVERS b/doc/NEWDRIVERS
new file mode 100644
index 0000000..c52ca2b
--- /dev/null
+++ b/doc/NEWDRIVERS
@@ -0,0 +1,18 @@
+This is a short intro for writing new AP drivers for changing WEP keys
+----------------------------------------------------------------------
+
+If you plan to implement a new driver for chaning WEP keys for APs
+consider the following points:
+
+1) Have a look on src/iwkey.[ch]. That is the implementation for
+ changing WEP keys on the local machine by using the Linux wireless
+ extensions. Create a new copy of these files and adjust it to your
+ needs. You have to create a new global instance of "struct key_api"
+ and fill it in.
+
+2) Edit src/keyapi.c and modify key_api_get() to return your structure
+ you defined earlier when the given argument matches your driver.
+
+3) Make a patch and send it to me.
+
+$Id$
diff --git a/man/Makefile.am b/man/Makefile.am
new file mode 100644
index 0000000..11ac17d
--- /dev/null
+++ b/man/Makefile.am
@@ -0,0 +1,40 @@
+# $Id$
+
+# This file is part of aeswepd.
+#
+# aeswepd 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.
+#
+# aeswepd 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 aeswepd; if not, write to the Free Software Foundation,
+# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+
+man_MANS = aeswepd.8 aeswepls.8
+
+noinst_DATA = aeswepd.8.xml
+
+EXTRA_DIST = $(man_MANS) aeswepd.8.xml.in man.css man.xsl
+
+CLEANFILES = aeswepd.8.xml aeswepls.8
+
+aeswepd.8.xml: aeswepd.8.xml.in Makefile
+ sed -e 's,@sysconfdir\@,$(sysconfdir),g' -e 's,@sbindir\@,$(sbindir),g' -e 's,@PACKAGE_BUGREPORT\@,$(PACKAGE_BUGREPORT),g' -e 's,@PACKAGE_URL\@,$(PACKAGE_URL),g' $< > $@
+
+if USE_XMLTOMAN
+
+CLEANFILES += $(man_MANS)
+
+aeswepd.8: aeswepd.8.xml Makefile
+ xmltoman $< > $@
+
+endif
+
+aeswepls.8: aeswepd.8
+ ln -sf $< $@
diff --git a/man/aeswepd.8.xml.in b/man/aeswepd.8.xml.in
new file mode 100644
index 0000000..3fb3557
--- /dev/null
+++ b/man/aeswepd.8.xml.in
@@ -0,0 +1,175 @@
+<?xml version="1.0" standalone='no'?>
+<!DOCTYPE manpage SYSTEM "man.dtd">
+<?xml-stylesheet type="text/xsl" href="man.xsl" ?>
+
+<!-- $Id$ -->
+
+<!--
+ This file is part of aeswepd.
+
+ aeswepd 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.
+
+ aeswepd 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 aeswepd; if not, write to the Free Software Foundation,
+ Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+-->
+
+ <manpage name="aeswepd" section="8" desc="AES Rekeying Daemon for IEEE 802.11 WEP">
+
+ <synopsis>
+ <cmd>aeswepd [<arg>options</arg>]</cmd>
+ <cmd>aeswepls [<arg>options</arg>]</cmd>
+ </synopsis>
+
+ <description>
+ <p>aeswepd is UNIX daemon for changing WEP keys of WLAN devices
+ in constant intervals. The WEP keys are calculated by encrypting
+ the current UNIX time using the AES cypher with a given constant
+ key. aeswepd is intended to increase the security of the
+ hardware based, standards compliant WEP technology. </p>
+
+ <p>aeswepd may use up to three hardware WEP keys: the first is
+ set to the current, the second to the previous and the third to
+ the next key. This is useful when working with not completely
+ synchronized RTCs. If only a single hardware WEP key is used, you
+ have to synchronize your RTCs so that no connectivity interrupts
+ may occur.</p>
+
+ <p>Currently, aeswepd is able to modify the WEP keys of local
+ network devices providing the Linux wireless extensions only.</p>
+
+ <p>aeswepls may be used to query the current keys of a running
+ daemon for the specified interface.</p>
+
+ </description>
+
+ <options>
+
+ <option>
+ <p><opt>-n | --no-daemon</opt></p>
+ <optdesc><p>
+ Do not daemonize (for debugging) (default: off)
+ </p></optdesc>
+ </option>
+
+ <option>
+ <p><opt>-s | --no-syslog</opt></p>
+ <optdesc><p>
+ Do not use syslog, use stdout instead (for debugging) (default: off).
+ </p></optdesc>
+ </option>
+
+ <option>
+ <p><opt>-i | --iface=</opt> <arg>IFACE</arg></p>
+ <optdesc><p>
+ Specify ethernet interface (default: eth0)
+ </p></optdesc>
+ </option>
+
+ <option>
+ <p><opt>-w | --wait-on-fork</opt></p>
+
+ <optdesc><p> When daemonizing, wait until the background
+ process finished with the initial link beat detection. When
+ this is enabled, the parent process will return the link
+ status on exit. 1 means link beat detected, 2 stands for link
+ beat not detected, everything else is an error.
+ </p></optdesc>
+ </option>
+
+ <option>
+ <p><opt>-t | --rekey-time=</opt> <arg>SEC</arg></p>
+ <optdesc><p>Specify the rekeying interval in seconds.</p></optdesc>
+ </option>
+
+ <option>
+ <p><opt>-K | --key</opt> <arg>KEY</arg></p>
+ <optdesc><p>Specify the AES key to use. Don't use this options, since users may get access to the key by running <file>ps</file>.</p></optdesc>
+ </option>
+
+ <option>
+ <p><opt>-E | --keye-env</opt> <arg>ENV</arg></p>
+ <optdesc><p>Specify an environment variable to read the AES key to use from.</p></optdesc>
+ </option>
+
+ <option>
+ <p><opt>-F | --key-file</opt> <arg>FILE</arg></p>
+ <optdesc><p>Specify a file to read the AES key to use from.</p></optdesc>
+ </option>
+
+ <option>
+ <p><opt>-m | --max-keys=</opt> <arg>NR</arg></p>
+ <optdesc><p>Specify how many hardware WEP keys are to be used
+ by aeswepd. Currently only 1 and 3 are supported. Most 802.11
+ hardware is capable to use up to four distinct WEP keys
+ concurrently.</p></optdesc>
+ </option>
+
+ <option>
+ <p><opt>-l | --list-keys</opt></p>
+ <optdesc><p>Show keys of running daemon for the specified interface. This is implied if the binary is called as <file>aeswepls</file></p></optdesc>
+ </option>
+
+ <option>
+ <p><opt>-h | --help</opt></p>
+ <optdesc><p>
+ Show help
+ </p></optdesc>
+ </option>
+
+ <option>
+ <p><opt>-k | --kill</opt></p>
+ <optdesc><p>
+ Kill a running daemon (Specify -i to select the daemon instance to kill)
+ </p></optdesc>
+ </option>
+
+ <option>
+ <p><opt>-c | --check-running</opt></p>
+ <optdesc><p>
+ Check if a daemon is running for a given network interface. Sets the return value to 0 if a daemon is already running or to 255 if not.
+ </p></optdesc>
+ </option>
+
+ <option>
+ <p><opt>-v | --version</opt></p>
+ <optdesc><p>
+ Show version
+ </p></optdesc>
+ </option>
+
+ </options>
+
+ <section name="Signals">
+ <p><arg>SIGINT, SIGTERM, SIGTQUIT</arg> aeswepd will quit. This is issued by passing -k to aeswepd.</p>
+ <p><arg>SIGHUP</arg> aeswepd will rekey immediately.</p>
+ </section>
+
+ <section name="Author">
+ <p>aeswepd was written by Lennart Poettering
+ &lt;@PACKAGE_BUGREPORT@&gt;. aeswepd is available
+ at <url
+ href="@PACKAGE_URL@"/>
+ </p>
+ </section>
+
+ <section name="See also">
+ <p>
+ <manref name="waproamd" section="8"/>, <manref name="iwconfig" section="8"/>
+ </p>
+ </section>
+
+ <section name="Comments">
+ <p>This man page was written using <manref name="xmltoman" section="1"
+ href="http://masqmail.cx/xml2man/"/> by Oliver Kurth.</p>
+ </section>
+
+ </manpage>
diff --git a/man/man.css b/man/man.css
new file mode 100644
index 0000000..0892e4f
--- /dev/null
+++ b/man/man.css
@@ -0,0 +1,30 @@
+/* $Id$ */
+
+/***
+ This file is part of ifplugd.
+
+ ifplugd 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.
+
+ ifplugd 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 ifplugd; if not, write to the Free Software Foundation,
+ Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+***/
+
+body { color: black; background-color: white; margin: 0.5cm; }
+a:link, a:visited { color: #900000; }
+h1 { text-transform:uppercase; font-size: 18pt; color: #00009F; }
+p { margin-left:1cm; margin-right:1cm; }
+.cmd { font-family:monospace; }
+.file { font-family:monospace; }
+.arg { text-transform:uppercase; font-family:monospace; font-style: italic; }
+.opt { font-family:monospace; font-weight: bold; }
+.manref { font-family:monospace; }
+.option .optdesc { margin-left:2cm; }
diff --git a/man/man.xsl b/man/man.xsl
new file mode 100644
index 0000000..e633de1
--- /dev/null
+++ b/man/man.xsl
@@ -0,0 +1,120 @@
+<?xml version="1.0" encoding="iso-8859-1"?>
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml">
+
+<!--
+ This file is part of ifplugd.
+
+ ifplugd 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.
+
+ ifplugd 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 ifplugd; if not, write to the Free Software Foundation,
+ Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+-->
+
+<xsl:template match="/manpage">
+ <xsl:text disable-output-escaping="yes">
+ &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;
+ </xsl:text>
+ <html>
+
+ <head>
+ <title>
+ <xsl:value-of select="@name"/>(<xsl:value-of select="@section"/>)
+ </title>
+ <link rel="stylesheet" type="text/css" href="man.css"/>
+ </head>
+ <body>
+ <h1>Name</h1>
+ <p><xsl:value-of select="@name"/>
+ <xsl:if test="string-length(@desc) &gt; 0">
+ - <xsl:value-of select="@desc"/>
+ </xsl:if>
+ </p>
+ <xsl:apply-templates />
+ </body>
+ </html>
+</xsl:template>
+
+<xsl:template match="p">
+ <p>
+ <xsl:apply-templates/>
+ </p>
+</xsl:template>
+
+<xsl:template match="cmd">
+ <p class="cmd">
+ <xsl:apply-templates/>
+ </p>
+</xsl:template>
+
+<xsl:template match="arg">
+ <span class="arg"><xsl:apply-templates/></span>
+</xsl:template>
+
+<xsl:template match="opt">
+ <span class="opt"><xsl:apply-templates/></span>
+</xsl:template>
+
+<xsl:template match="file">
+ <span class="file"><xsl:apply-templates/></span>
+</xsl:template>
+
+<xsl:template match="optdesc">
+ <div class="optdesc">
+ <xsl:apply-templates/>
+ </div>
+</xsl:template>
+
+<xsl:template match="synopsis">
+ <h1>Synopsis</h1>
+ <xsl:apply-templates/>
+</xsl:template>
+
+<xsl:template match="seealso">
+ <h1>Synopsis</h1>
+ <xsl:apply-templates/>
+</xsl:template>
+
+<xsl:template match="description">
+ <h1>Description</h1>
+ <xsl:apply-templates/>
+</xsl:template>
+
+<xsl:template match="options">
+ <h1>Options</h1>
+ <xsl:apply-templates/>
+</xsl:template>
+
+<xsl:template match="section">
+ <h1><xsl:value-of select="@name"/></h1>
+ <xsl:apply-templates/>
+</xsl:template>
+
+<xsl:template match="option">
+ <div class="option"><xsl:apply-templates/></div>
+</xsl:template>
+
+<xsl:template match="manref">
+ <xsl:choose>
+ <xsl:when test="string-length(@href) &gt; 0">
+ <a class="manref"><xsl:attribute name="href"><xsl:value-of select="@href"/></xsl:attribute><xsl:value-of select="@name"/>(<xsl:value-of select="@section"/>)</a>
+ </xsl:when>
+ <xsl:otherwise>
+ <span class="manref"><xsl:value-of select="@name"/>(<xsl:value-of select="@section"/>)</span>
+ </xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+
+<xsl:template match="url">
+ <a class="url"><xsl:attribute name="href"><xsl:value-of select="@href"/></xsl:attribute><xsl:value-of select="@href"/></a>
+</xsl:template>
+
+</xsl:stylesheet>
diff --git a/src/Makefile.am b/src/Makefile.am
index ce00817..8e5d700 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -24,7 +24,7 @@ aeswepd_SOURCES = aeswepd.c aeswepd.h \
iwkey.c iwkey.h \
util.c util.h \
wireless.h wireless.15.h \
- netlink.h rtnetlink.h
+ keyapi.c keyapi.h
aeswepd_LDADD = -lmcrypt
diff --git a/src/aeswepd.c b/src/aeswepd.c
index 11e77c8..2975647 100644
--- a/src/aeswepd.c
+++ b/src/aeswepd.c
@@ -32,6 +32,7 @@
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
+#include <limits.h>
#include <libdaemon/dlog.h>
#include <libdaemon/dpid.h>
@@ -40,9 +41,8 @@
#include "aes.h"
#include "aeswepd.h"
-#include "iwkey.h"
-#include "interface.h"
#include "util.h"
+#include "keyapi.h"
uint8_t aes_key[AES_KEY_LEN];
int rekey_time = 15*60;
@@ -115,11 +115,11 @@ int print_wep_key(FILE *f, int t, uint8_t wep[WEP_KEY_LEN]) {
}
-int rekey(struct interface *i, time_t now, time_t *next_rekey) {
+int rekey(const struct key_api *ka, void *c, time_t now, time_t *next_rekey) {
uint8_t w[WEP_KEY_LEN];
uint32_t t;
- assert(i && n_max_keys >= 1 && next_rekey);
+ assert(n_max_keys >= 1 && next_rekey && ka);
t = now/rekey_time;
@@ -133,7 +133,7 @@ int rekey(struct interface *i, time_t now, time_t *next_rekey) {
if (wep_key_calc(t, w) < 0)
return -1;
- if (wep_key_add(i, w) < 0)
+ if (ka->add(c, w) < 0)
return -1;
if (status_file)
@@ -143,7 +143,7 @@ int rekey(struct interface *i, time_t now, time_t *next_rekey) {
if (wep_key_calc(t-1, w) < 0)
return -1;
- if (wep_key_add(i, w) < 0)
+ if (ka->add(c, w) < 0)
return -1;
if (status_file)
@@ -152,7 +152,7 @@ int rekey(struct interface *i, time_t now, time_t *next_rekey) {
if (wep_key_calc(t+1, w) < 0)
return -1;
- if (wep_key_add(i, w) < 0)
+ if (ka->add(c, w) < 0)
return -1;
if (status_file)
@@ -162,7 +162,7 @@ int rekey(struct interface *i, time_t now, time_t *next_rekey) {
if (status_file)
fflush(status_file);
- if (wep_key_finish(i) < 0)
+ if (ka->finish(c) < 0)
return -1;
*next_rekey = (t+1)*rekey_time;
@@ -170,12 +170,14 @@ int rekey(struct interface *i, time_t now, time_t *next_rekey) {
return 0;
}
-int go(struct interface *i) {
+int go(void) {
time_t next_rekey = 0;
int send_retval = 1;
fd_set fds;
time_t now = time(NULL);
int sigfd, r = -1;
+ void *c = NULL;
+ const struct key_api *ka = NULL;
daemon_log(LOG_INFO, "aeswepd "VERSION" initializing. (rekey_time=%i)", rekey_time);
@@ -201,8 +203,16 @@ int go(struct interface *i) {
use_status_file = 0;
}
}
+
+ if (!(ka = key_api_get(interface_name))) {
+ daemon_log(LOG_ERR, "Failed to find key API for specified interface %s", interface_name);
+ goto finish;
+ }
+
+ if (!(c = ka->open(interface_name)))
+ goto finish;
- if (rekey(i, now, &next_rekey) < 0)
+ if (rekey(ka, c, now, &next_rekey) < 0)
goto finish;
daemon_log(LOG_INFO, "aeswepd successfully initialized.");
@@ -221,7 +231,7 @@ int go(struct interface *i) {
now = time(NULL);
if (next_rekey < now) {
- if (rekey(i, now, &next_rekey) < 0)
+ if (rekey(ka, c, now, &next_rekey) < 0)
return -1;
}
@@ -273,6 +283,12 @@ int go(struct interface *i) {
finish:
+ if (c && ka) {
+ ka->close(c);
+ c = NULL;
+ }
+
+
if (status_file) {
fclose(status_file);
unlink(get_status_file_name());
@@ -293,7 +309,7 @@ void usage(char *p) {
if (strrchr(p, '/'))
p = strchr(p, '/')+1;
- printf("%s -- AES Rekeying Daemon for IEEE 802.11b WEP\n\n"
+ printf("%s -- AES Rekeying Daemon for IEEE 802.11 WEP\n\n"
"Usage: %s [options]\n\n"
"Options:\n"
" -n --no-daemon Do not daemonize (for debugging) (%s)\n"
@@ -407,7 +423,7 @@ void parse_args(int argc, char *argv[]) {
break;
case 'K':
- daemon_log(LOG_WARNING, "WARNING: Don't use the --key option, other local users might peek on 'ps'. Proceeding");
+ daemon_log(LOG_WARNING, "WARNING: Don't use the --key option, other local users might peek on 'ps'. Proceeding anyway.");
strncpy(ln, optarg, sizeof(ln)-1);
ln[sizeof(ln)-1] = 0;
_key_set = 1;
@@ -528,7 +544,6 @@ void parse_args(int argc, char *argv[]) {
}
int main(int argc, char *argv[]) {
- struct interface *i = NULL;
int r = 1, j;
pid_t pid;
@@ -560,17 +575,17 @@ int main(int argc, char *argv[]) {
goto finish;
if (pid) {
- int c = 0;
-
// Parent process
- if (wait_on_fork)
- if ((c = daemon_retval_wait(60)) < 0) {
+ if (wait_on_fork) {
+ if ((r = daemon_retval_wait(60)) < 0) {
daemon_log(LOG_WARNING, "Killing background process.");
kill(pid, SIGTERM);
+ r = 1;
}
+ } else
+ r = 0;
- r = c;
goto finish;
}
}
@@ -579,19 +594,13 @@ int main(int argc, char *argv[]) {
for (j = 0; j < MAX_WEP_KEYS; j++)
key_map[j] = j;
- if (!(i = interface_open(interface_name)) < 0)
- goto finish;
-
- if (go(i) < 0)
+ if (go() < 0)
goto finish;
r = 0;
finish:
- if (i)
- interface_close(i);
-
if (interface_name)
free(interface_name);
diff --git a/src/interface.c b/src/interface.c
index 4f1605a..b33472c 100644
--- a/src/interface.c
+++ b/src/interface.c
@@ -64,47 +64,3 @@ void interface_close(struct interface *i) {
free(i);
}
-
-int interface_is_assoc(struct interface *i, struct hw_addr *ap) {
- struct hw_addr ap2;
- struct iwreq req;
- struct iw_statistics q;
-
- assert(i);
-
- if (ap)
- memset(ap->addr, 0, ETH_ALEN);
-
- memset(&req, 0, sizeof(req));
- strncpy(req.ifr_ifrn.ifrn_name, i->name, IFNAMSIZ);
-
- if (ioctl(i->fd, SIOCGIWAP, &req) < 0) {
- daemon_log(LOG_ERR, "Failed to get AP address\n");
- return -1;
- }
-
- memcpy(ap2.addr, &(req.u.ap_addr.sa_data), ETH_ALEN);
-
- if (!is_assoc_ap(&ap2))
- return 0;
-
- memset(&req, 0, sizeof(req));
- strncpy(req.ifr_ifrn.ifrn_name, i->name, IFNAMSIZ);
-
- req.u.data.pointer = (caddr_t) &q;
- req.u.data.length = sizeof(q);
- req.u.data.flags = 1;
-
- if (ioctl(i->fd, SIOCGIWSTATS, &req) < 0) {
- daemon_log(LOG_ERR, "Failed to get interface quality\n");
- return -1;
- }
-
- if (q.qual.qual <= 0)
- return 0;
-
- if (ap)
- memcpy(ap->addr, ap2.addr, ETH_ALEN);
-
- return 1;
-}
diff --git a/src/interface.h b/src/interface.h
index b0667a8..fe803ef 100644
--- a/src/interface.h
+++ b/src/interface.h
@@ -32,6 +32,5 @@ struct interface {
struct interface *interface_open(char *name);
void interface_close(struct interface *i);
-int interface_is_assoc(struct interface *i, struct hw_addr *a);
#endif
diff --git a/src/iwkey.c b/src/iwkey.c
index 719c31a..bebe1bc 100644
--- a/src/iwkey.c
+++ b/src/iwkey.c
@@ -26,13 +26,15 @@
#include <libdaemon/dlog.h>
+#include "keyapi.h"
#include "iwkey.h"
#include "wireless.h"
#include "util.h"
+#include "interface.h"
static int n_used_keys = 0;
-int wep_key_add(struct interface *i, uint8_t w[WEP_KEY_LEN]) {
+static int wep_key_add(struct interface *i, const uint8_t w[WEP_KEY_LEN]) {
struct iwreq req;
assert(i);
@@ -44,7 +46,7 @@ int wep_key_add(struct interface *i, uint8_t w[WEP_KEY_LEN]) {
memset(&req, 0, sizeof(req));
strncpy(req.ifr_ifrn.ifrn_name, i->name, IFNAMSIZ);
- req.u.encoding.pointer = w;
+ req.u.encoding.pointer = (uint8_t*) w;
req.u.encoding.length = WEP_KEY_LEN;
req.u.encoding.flags = key_map[n_used_keys++]+1;
@@ -56,7 +58,7 @@ int wep_key_add(struct interface *i, uint8_t w[WEP_KEY_LEN]) {
return 0;
}
-int wep_key_finish(struct interface *i) {
+static int wep_key_finish(struct interface *i) {
struct iwreq req;
assert(i);
@@ -107,3 +109,11 @@ int wep_key_finish(struct interface *i) {
return 0;
}
+
+
+const struct key_api linux_key_api = {
+ open: (void*) interface_open,
+ close: (void*) interface_close,
+ add: (void*) wep_key_add,
+ finish: (void*) wep_key_finish
+};
diff --git a/src/iwkey.h b/src/iwkey.h
index 4e853c0..72489b3 100644
--- a/src/iwkey.h
+++ b/src/iwkey.h
@@ -21,11 +21,8 @@
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*/
-#include <stdint.h>
-#include "interface.h"
-#include "aeswepd.h"
+#include "keyapi.h"
-int wep_key_add(struct interface *i, uint8_t w[WEP_KEY_LEN]);
-int wep_key_finish(struct interface *i);
+const extern struct key_api linux_key_api;
#endif
diff --git a/src/keyapi.c b/src/keyapi.c
new file mode 100644
index 0000000..a67012d
--- /dev/null
+++ b/src/keyapi.c
@@ -0,0 +1,29 @@
+/* $Id$ */
+
+/*
+ * This file is part of aeswepd.
+ *
+ * aeswepd 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.
+ *
+ * aeswepd 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 aeswepd; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+
+#include "iwkey.h"
+
+const struct key_api * key_api_get(const char *c) {
+
+ /* Match for any special driver here ... */
+
+ return &linux_key_api;
+}
+
diff --git a/src/keyapi.h b/src/keyapi.h
new file mode 100644
index 0000000..14fe341
--- /dev/null
+++ b/src/keyapi.h
@@ -0,0 +1,37 @@
+#ifndef fookeyapihfoo
+#define fookeyapihfoo
+
+/* $Id$ */
+
+/*
+ * This file is part of aeswepd.
+ *
+ * aeswepd 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.
+ *
+ * aeswepd 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 aeswepd; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+
+#include <stdint.h>
+
+#include "aeswepd.h"
+
+struct key_api {
+ void* (*open)(const char* name);
+ int (*add)(void *c, const uint8_t w[WEP_KEY_LEN]);
+ int (*finish)(void *c);
+ void (*close)(void *c);
+};
+
+const struct key_api* key_api_get(const char *c);
+
+#endif
diff --git a/src/netlink.h b/src/netlink.h
deleted file mode 100644
index ccfdc2d..0000000
--- a/src/netlink.h
+++ /dev/null
@@ -1,177 +0,0 @@
-#ifndef __LINUX_NETLINK_H
-#define __LINUX_NETLINK_H
-
-#include <linux/socket.h> /* for sa_family_t */
-
-#define NETLINK_ROUTE 0 /* Routing/device hook */
-#define NETLINK_SKIP 1 /* Reserved for ENskip */
-#define NETLINK_USERSOCK 2 /* Reserved for user mode socket protocols */
-#define NETLINK_FIREWALL 3 /* Firewalling hook */
-#define NETLINK_TCPDIAG 4 /* TCP socket monitoring */
-#define NETLINK_NFLOG 5 /* netfilter/iptables ULOG */
-#define NETLINK_XFRM 6 /* ipsec */
-#define NETLINK_ARPD 8
-#define NETLINK_ROUTE6 11 /* af_inet6 route comm channel */
-#define NETLINK_IP6_FW 13
-#define NETLINK_DNRTMSG 14 /* DECnet routing messages */
-#define NETLINK_TAPBASE 16 /* 16 to 31 are ethertap */
-
-#define MAX_LINKS 32
-
-struct sockaddr_nl
-{
- sa_family_t nl_family; /* AF_NETLINK */
- unsigned short nl_pad; /* zero */
- __u32 nl_pid; /* process pid */
- __u32 nl_groups; /* multicast groups mask */
-};
-
-struct nlmsghdr
-{
- __u32 nlmsg_len; /* Length of message including header */
- __u16 nlmsg_type; /* Message content */
- __u16 nlmsg_flags; /* Additional flags */
- __u32 nlmsg_seq; /* Sequence number */
- __u32 nlmsg_pid; /* Sending process PID */
-};
-
-/* Flags values */
-
-#define NLM_F_REQUEST 1 /* It is request message. */
-#define NLM_F_MULTI 2 /* Multipart message, terminated by NLMSG_DONE */
-#define NLM_F_ACK 4 /* Reply with ack, with zero or error code */
-#define NLM_F_ECHO 8 /* Echo this request */
-
-/* Modifiers to GET request */
-#define NLM_F_ROOT 0x100 /* specify tree root */
-#define NLM_F_MATCH 0x200 /* return all matching */
-#define NLM_F_ATOMIC 0x400 /* atomic GET */
-#define NLM_F_DUMP (NLM_F_ROOT|NLM_F_MATCH)
-
-/* Modifiers to NEW request */
-#define NLM_F_REPLACE 0x100 /* Override existing */
-#define NLM_F_EXCL 0x200 /* Do not touch, if it exists */
-#define NLM_F_CREATE 0x400 /* Create, if it does not exist */
-#define NLM_F_APPEND 0x800 /* Add to end of list */
-
-/*
- 4.4BSD ADD NLM_F_CREATE|NLM_F_EXCL
- 4.4BSD CHANGE NLM_F_REPLACE
-
- True CHANGE NLM_F_CREATE|NLM_F_REPLACE
- Append NLM_F_CREATE
- Check NLM_F_EXCL
- */
-
-#define NLMSG_ALIGNTO 4
-#define NLMSG_ALIGN(len) ( ((len)+NLMSG_ALIGNTO-1) & ~(NLMSG_ALIGNTO-1) )
-#define NLMSG_LENGTH(len) ((len)+NLMSG_ALIGN(sizeof(struct nlmsghdr)))
-#define NLMSG_SPACE(len) NLMSG_ALIGN(NLMSG_LENGTH(len))
-#define NLMSG_DATA(nlh) ((void*)(((char*)nlh) + NLMSG_LENGTH(0)))
-#define NLMSG_NEXT(nlh,len) ((len) -= NLMSG_ALIGN((nlh)->nlmsg_len), \
- (struct nlmsghdr*)(((char*)(nlh)) + NLMSG_ALIGN((nlh)->nlmsg_len)))
-#define NLMSG_OK(nlh,len) ((len) > 0 && (nlh)->nlmsg_len >= sizeof(struct nlmsghdr) && \
- (nlh)->nlmsg_len <= (len))
-#define NLMSG_PAYLOAD(nlh,len) ((nlh)->nlmsg_len - NLMSG_SPACE((len)))
-
-#define NLMSG_NOOP 0x1 /* Nothing. */
-#define NLMSG_ERROR 0x2 /* Error */
-#define NLMSG_DONE 0x3 /* End of a dump */
-#define NLMSG_OVERRUN 0x4 /* Data lost */
-
-struct nlmsgerr
-{
- int error;
- struct nlmsghdr msg;
-};
-
-#define NET_MAJOR 36 /* Major 36 is reserved for networking */
-
-#ifdef __KERNEL__
-
-#include <linux/capability.h>
-#include <linux/skbuff.h>
-
-struct netlink_skb_parms
-{
- struct ucred creds; /* Skb credentials */
- __u32 pid;
- __u32 groups;
- __u32 dst_pid;
- __u32 dst_groups;
- kernel_cap_t eff_cap;
-};
-
-#define NETLINK_CB(skb) (*(struct netlink_skb_parms*)&((skb)->cb))
-#define NETLINK_CREDS(skb) (&NETLINK_CB((skb)).creds)
-
-
-extern int netlink_attach(int unit, int (*function)(int,struct sk_buff *skb));
-extern void netlink_detach(int unit);
-extern int netlink_post(int unit, struct sk_buff *skb);
-extern int init_netlink(void);
-extern struct sock *netlink_kernel_create(int unit, void (*input)(struct sock *sk, int len));
-extern void netlink_ack(struct sk_buff *in_skb, struct nlmsghdr *nlh, int err);
-extern int netlink_unicast(struct sock *ssk, struct sk_buff *skb, __u32 pid, int nonblock);
-extern int netlink_broadcast(struct sock *ssk, struct sk_buff *skb, __u32 pid,
- __u32 group, int allocation);
-extern void netlink_set_err(struct sock *ssk, __u32 pid, __u32 group, int code);
-extern int netlink_register_notifier(struct notifier_block *nb);
-extern int netlink_unregister_notifier(struct notifier_block *nb);
-
-/*
- * skb should fit one page. This choice is good for headerless malloc.
- *
- * FIXME: What is the best size for SLAB???? --ANK
- */
-#define NLMSG_GOODSIZE (PAGE_SIZE - ((sizeof(struct sk_buff)+0xF)&~0xF))
-
-
-struct netlink_callback
-{
- struct sk_buff *skb;
- struct nlmsghdr *nlh;
- int (*dump)(struct sk_buff * skb, struct netlink_callback *cb);
- int (*done)(struct netlink_callback *cb);
- int family;
- long args[4];
-};
-
-struct netlink_notify
-{
- int pid;
- int protocol;
-};
-
-static __inline__ struct nlmsghdr *
-__nlmsg_put(struct sk_buff *skb, u32 pid, u32 seq, int type, int len)
-{
- struct nlmsghdr *nlh;
- int size = NLMSG_LENGTH(len);
-
- nlh = (struct nlmsghdr*)skb_put(skb, NLMSG_ALIGN(size));
- nlh->nlmsg_type = type;
- nlh->nlmsg_len = size;
- nlh->nlmsg_flags = 0;
- nlh->nlmsg_pid = pid;
- nlh->nlmsg_seq = seq;
- return nlh;
-}
-
-#define NLMSG_PUT(skb, pid, seq, type, len) \
-({ if (skb_tailroom(skb) < (int)NLMSG_SPACE(len)) goto nlmsg_failure; \
- __nlmsg_put(skb, pid, seq, type, len); })
-
-extern int netlink_dump_start(struct sock *ssk, struct sk_buff *skb,
- struct nlmsghdr *nlh,
- int (*dump)(struct sk_buff *skb, struct netlink_callback*),
- int (*done)(struct netlink_callback*));
-
-#define NL_NONROOT_RECV 0x1
-#define NL_NONROOT_SEND 0x2
-extern void netlink_set_nonroot(int protocol, unsigned flag);
-
-
-#endif /* __KERNEL__ */
-
-#endif /* __LINUX_NETLINK_H */
diff --git a/src/rtnetlink.h b/src/rtnetlink.h
deleted file mode 100644
index f16fb11..0000000
--- a/src/rtnetlink.h
+++ /dev/null
@@ -1,631 +0,0 @@
-#ifndef __LINUX_RTNETLINK_H
-#define __LINUX_RTNETLINK_H
-
-#include <linux/netlink.h>
-
-#define RTNL_DEBUG 1
-
-
-/****
- * Routing/neighbour discovery messages.
- ****/
-
-/* Types of messages */
-
-#define RTM_BASE 0x10
-
-#define RTM_NEWLINK (RTM_BASE+0)
-#define RTM_DELLINK (RTM_BASE+1)
-#define RTM_GETLINK (RTM_BASE+2)
-
-#define RTM_NEWADDR (RTM_BASE+4)
-#define RTM_DELADDR (RTM_BASE+5)
-#define RTM_GETADDR (RTM_BASE+6)
-
-#define RTM_NEWROUTE (RTM_BASE+8)
-#define RTM_DELROUTE (RTM_BASE+9)
-#define RTM_GETROUTE (RTM_BASE+10)
-
-#define RTM_NEWNEIGH (RTM_BASE+12)
-#define RTM_DELNEIGH (RTM_BASE+13)
-#define RTM_GETNEIGH (RTM_BASE+14)
-
-#define RTM_NEWRULE (RTM_BASE+16)
-#define RTM_DELRULE (RTM_BASE+17)
-#define RTM_GETRULE (RTM_BASE+18)
-
-#define RTM_NEWQDISC (RTM_BASE+20)
-#define RTM_DELQDISC (RTM_BASE+21)
-#define RTM_GETQDISC (RTM_BASE+22)
-
-#define RTM_NEWTCLASS (RTM_BASE+24)
-#define RTM_DELTCLASS (RTM_BASE+25)
-#define RTM_GETTCLASS (RTM_BASE+26)
-
-#define RTM_NEWTFILTER (RTM_BASE+28)
-#define RTM_DELTFILTER (RTM_BASE+29)
-#define RTM_GETTFILTER (RTM_BASE+30)
-
-#define RTM_MAX (RTM_BASE+31)
-
-/*
- Generic structure for encapsulation of optional route information.
- It is reminiscent of sockaddr, but with sa_family replaced
- with attribute type.
- */
-
-struct rtattr
-{
- unsigned short rta_len;
- unsigned short rta_type;
-};
-
-/* Macros to handle rtattributes */
-
-#define RTA_ALIGNTO 4
-#define RTA_ALIGN(len) ( ((len)+RTA_ALIGNTO-1) & ~(RTA_ALIGNTO-1) )
-#define RTA_OK(rta,len) ((len) > 0 && (rta)->rta_len >= sizeof(struct rtattr) && \
- (rta)->rta_len <= (len))
-#define RTA_NEXT(rta,attrlen) ((attrlen) -= RTA_ALIGN((rta)->rta_len), \
- (struct rtattr*)(((char*)(rta)) + RTA_ALIGN((rta)->rta_len)))
-#define RTA_LENGTH(len) (RTA_ALIGN(sizeof(struct rtattr)) + (len))
-#define RTA_SPACE(len) RTA_ALIGN(RTA_LENGTH(len))
-#define RTA_DATA(rta) ((void*)(((char*)(rta)) + RTA_LENGTH(0)))
-#define RTA_PAYLOAD(rta) ((int)((rta)->rta_len) - RTA_LENGTH(0))
-
-
-
-
-/******************************************************************************
- * Definitions used in routing table administration.
- ****/
-
-struct rtmsg
-{
- unsigned char rtm_family;
- unsigned char rtm_dst_len;
- unsigned char rtm_src_len;
- unsigned char rtm_tos;
-
- unsigned char rtm_table; /* Routing table id */
- unsigned char rtm_protocol; /* Routing protocol; see below */
- unsigned char rtm_scope; /* See below */
- unsigned char rtm_type; /* See below */
-
- unsigned rtm_flags;
-};
-
-/* rtm_type */
-
-enum
-{
- RTN_UNSPEC,
- RTN_UNICAST, /* Gateway or direct route */
- RTN_LOCAL, /* Accept locally */
- RTN_BROADCAST, /* Accept locally as broadcast,
- send as broadcast */
- RTN_ANYCAST, /* Accept locally as broadcast,
- but send as unicast */
- RTN_MULTICAST, /* Multicast route */
- RTN_BLACKHOLE, /* Drop */
- RTN_UNREACHABLE, /* Destination is unreachable */
- RTN_PROHIBIT, /* Administratively prohibited */
- RTN_THROW, /* Not in this table */
- RTN_NAT, /* Translate this address */
- RTN_XRESOLVE, /* Use external resolver */
-};
-
-#define RTN_MAX RTN_XRESOLVE
-
-
-/* rtm_protocol */
-
-#define RTPROT_UNSPEC 0
-#define RTPROT_REDIRECT 1 /* Route installed by ICMP redirects;
- not used by current IPv4 */
-#define RTPROT_KERNEL 2 /* Route installed by kernel */
-#define RTPROT_BOOT 3 /* Route installed during boot */
-#define RTPROT_STATIC 4 /* Route installed by administrator */
-
-/* Values of protocol >= RTPROT_STATIC are not interpreted by kernel;
- they are just passed from user and back as is.
- It will be used by hypothetical multiple routing daemons.
- Note that protocol values should be standardized in order to
- avoid conflicts.
- */
-
-#define RTPROT_GATED 8 /* Apparently, GateD */
-#define RTPROT_RA 9 /* RDISC/ND router advertisements */
-#define RTPROT_MRT 10 /* Merit MRT */
-#define RTPROT_ZEBRA 11 /* Zebra */
-#define RTPROT_BIRD 12 /* BIRD */
-#define RTPROT_DNROUTED 13 /* DECnet routing daemon */
-
-/* rtm_scope
-
- Really it is not scope, but sort of distance to the destination.
- NOWHERE are reserved for not existing destinations, HOST is our
- local addresses, LINK are destinations, located on directly attached
- link and UNIVERSE is everywhere in the Universe.
-
- Intermediate values are also possible f.e. interior routes
- could be assigned a value between UNIVERSE and LINK.
-*/
-
-enum rt_scope_t
-{
- RT_SCOPE_UNIVERSE=0,
-/* User defined values */
- RT_SCOPE_SITE=200,
- RT_SCOPE_LINK=253,
- RT_SCOPE_HOST=254,
- RT_SCOPE_NOWHERE=255
-};
-
-/* rtm_flags */
-
-#define RTM_F_NOTIFY 0x100 /* Notify user of route change */
-#define RTM_F_CLONED 0x200 /* This route is cloned */
-#define RTM_F_EQUALIZE 0x400 /* Multipath equalizer: NI */
-#define RTM_F_PREFIX 0x800 /* Prefix addresses */
-
-/* Reserved table identifiers */
-
-enum rt_class_t
-{
- RT_TABLE_UNSPEC=0,
-/* User defined values */
- RT_TABLE_DEFAULT=253,
- RT_TABLE_MAIN=254,
- RT_TABLE_LOCAL=255
-};
-#define RT_TABLE_MAX RT_TABLE_LOCAL
-
-
-
-/* Routing message attributes */
-
-enum rtattr_type_t
-{
- RTA_UNSPEC,
- RTA_DST,
- RTA_SRC,
- RTA_IIF,
- RTA_OIF,
- RTA_GATEWAY,
- RTA_PRIORITY,
- RTA_PREFSRC,
- RTA_METRICS,
- RTA_MULTIPATH,
- RTA_PROTOINFO,
- RTA_FLOW,
- RTA_CACHEINFO,
- RTA_SESSION,
-};
-
-#define RTA_MAX RTA_SESSION
-
-#define RTM_RTA(r) ((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct rtmsg))))
-#define RTM_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct rtmsg))
-
-/* RTM_MULTIPATH --- array of struct rtnexthop.
- *
- * "struct rtnexthop" describes all necessary nexthop information,
- * i.e. parameters of path to a destination via this nexthop.
- *
- * At the moment it is impossible to set different prefsrc, mtu, window
- * and rtt for different paths from multipath.
- */
-
-struct rtnexthop
-{
- unsigned short rtnh_len;
- unsigned char rtnh_flags;
- unsigned char rtnh_hops;
- int rtnh_ifindex;
-};
-
-/* rtnh_flags */
-
-#define RTNH_F_DEAD 1 /* Nexthop is dead (used by multipath) */
-#define RTNH_F_PERVASIVE 2 /* Do recursive gateway lookup */
-#define RTNH_F_ONLINK 4 /* Gateway is forced on link */
-
-/* Macros to handle hexthops */
-
-#define RTNH_ALIGNTO 4
-#define RTNH_ALIGN(len) ( ((len)+RTNH_ALIGNTO-1) & ~(RTNH_ALIGNTO-1) )
-#define RTNH_OK(rtnh,len) ((rtnh)->rtnh_len >= sizeof(struct rtnexthop) && \
- ((int)(rtnh)->rtnh_len) <= (len))
-#define RTNH_NEXT(rtnh) ((struct rtnexthop*)(((char*)(rtnh)) + RTNH_ALIGN((rtnh)->rtnh_len)))
-#define RTNH_LENGTH(len) (RTNH_ALIGN(sizeof(struct rtnexthop)) + (len))
-#define RTNH_SPACE(len) RTNH_ALIGN(RTNH_LENGTH(len))
-#define RTNH_DATA(rtnh) ((struct rtattr*)(((char*)(rtnh)) + RTNH_LENGTH(0)))
-
-/* RTM_CACHEINFO */
-
-struct rta_cacheinfo
-{
- __u32 rta_clntref;
- __u32 rta_lastuse;
- __s32 rta_expires;
- __u32 rta_error;
- __u32 rta_used;
-
-#define RTNETLINK_HAVE_PEERINFO 1
- __u32 rta_id;
- __u32 rta_ts;
- __u32 rta_tsage;
-};
-
-/* RTM_METRICS --- array of struct rtattr with types of RTAX_* */
-
-enum
-{
- RTAX_UNSPEC,
-#define RTAX_UNSPEC RTAX_UNSPEC
- RTAX_LOCK,
-#define RTAX_LOCK RTAX_LOCK
- RTAX_MTU,
-#define RTAX_MTU RTAX_MTU
- RTAX_WINDOW,
-#define RTAX_WINDOW RTAX_WINDOW
- RTAX_RTT,
-#define RTAX_RTT RTAX_RTT
- RTAX_RTTVAR,
-#define RTAX_RTTVAR RTAX_RTTVAR
- RTAX_SSTHRESH,
-#define RTAX_SSTHRESH RTAX_SSTHRESH
- RTAX_CWND,
-#define RTAX_CWND RTAX_CWND
- RTAX_ADVMSS,
-#define RTAX_ADVMSS RTAX_ADVMSS
- RTAX_REORDERING,
-#define RTAX_REORDERING RTAX_REORDERING
- RTAX_HOPLIMIT,
-#define RTAX_HOPLIMIT RTAX_HOPLIMIT
- RTAX_INITCWND,
-#define RTAX_INITCWND RTAX_INITCWND
- RTAX_FEATURES,
-#define RTAX_FEATURES RTAX_FEATURES
-};
-
-#define RTAX_MAX RTAX_FEATURES
-
-#define RTAX_FEATURE_ECN 0x00000001
-#define RTAX_FEATURE_SACK 0x00000002
-#define RTAX_FEATURE_TIMESTAMP 0x00000004
-
-struct rta_session
-{
- __u8 proto;
-
- union {
- struct {
- __u16 sport;
- __u16 dport;
- } ports;
-
- struct {
- __u8 type;
- __u8 code;
- __u16 ident;
- } icmpt;
-
- __u32 spi;
- } u;
-};
-
-
-/*********************************************************
- * Interface address.
- ****/
-
-struct ifaddrmsg
-{
- unsigned char ifa_family;
- unsigned char ifa_prefixlen; /* The prefix length */
- unsigned char ifa_flags; /* Flags */
- unsigned char ifa_scope; /* See above */
- int ifa_index; /* Link index */
-};
-
-enum
-{
- IFA_UNSPEC,
- IFA_ADDRESS,
- IFA_LOCAL,
- IFA_LABEL,
- IFA_BROADCAST,
- IFA_ANYCAST,
- IFA_CACHEINFO
-};
-
-#define IFA_MAX IFA_CACHEINFO
-
-/* ifa_flags */
-
-#define IFA_F_SECONDARY 0x01
-#define IFA_F_TEMPORARY IFA_F_SECONDARY
-
-#define IFA_F_DEPRECATED 0x20
-#define IFA_F_TENTATIVE 0x40
-#define IFA_F_PERMANENT 0x80
-
-struct ifa_cacheinfo
-{
- __s32 ifa_prefered;
- __s32 ifa_valid;
-};
-
-
-#define IFA_RTA(r) ((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct ifaddrmsg))))
-#define IFA_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct ifaddrmsg))
-
-/*
- Important comment:
- IFA_ADDRESS is prefix address, rather than local interface address.
- It makes no difference for normally configured broadcast interfaces,
- but for point-to-point IFA_ADDRESS is DESTINATION address,
- local address is supplied in IFA_LOCAL attribute.
- */
-
-/**************************************************************
- * Neighbour discovery.
- ****/
-
-struct ndmsg
-{
- unsigned char ndm_family;
- unsigned char ndm_pad1;
- unsigned short ndm_pad2;
- int ndm_ifindex; /* Link index */
- __u16 ndm_state;
- __u8 ndm_flags;
- __u8 ndm_type;
-};
-
-enum
-{
- NDA_UNSPEC,
- NDA_DST,
- NDA_LLADDR,
- NDA_CACHEINFO
-};
-
-#define NDA_MAX NDA_CACHEINFO
-
-#define NDA_RTA(r) ((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct ndmsg))))
-#define NDA_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct ndmsg))
-
-/*
- * Neighbor Cache Entry Flags
- */
-
-#define NTF_PROXY 0x08 /* == ATF_PUBL */
-#define NTF_ROUTER 0x80
-
-/*
- * Neighbor Cache Entry States.
- */
-
-#define NUD_INCOMPLETE 0x01
-#define NUD_REACHABLE 0x02
-#define NUD_STALE 0x04
-#define NUD_DELAY 0x08
-#define NUD_PROBE 0x10
-#define NUD_FAILED 0x20
-
-/* Dummy states */
-#define NUD_NOARP 0x40
-#define NUD_PERMANENT 0x80
-#define NUD_NONE 0x00
-
-
-struct nda_cacheinfo
-{
- __u32 ndm_confirmed;
- __u32 ndm_used;
- __u32 ndm_updated;
- __u32 ndm_refcnt;
-};
-
-/****
- * General form of address family dependent message.
- ****/
-
-struct rtgenmsg
-{
- unsigned char rtgen_family;
-};
-
-/*****************************************************************
- * Link layer specific messages.
- ****/
-
-/* struct ifinfomsg
- * passes link level specific information, not dependent
- * on network protocol.
- */
-
-struct ifinfomsg
-{
- unsigned char ifi_family;
- unsigned char __ifi_pad;
- unsigned short ifi_type; /* ARPHRD_* */
- int ifi_index; /* Link index */
- unsigned ifi_flags; /* IFF_* flags */
- unsigned ifi_change; /* IFF_* change mask */
-};
-
-enum
-{
- IFLA_UNSPEC,
- IFLA_ADDRESS,
- IFLA_BROADCAST,
- IFLA_IFNAME,
- IFLA_MTU,
- IFLA_LINK,
- IFLA_QDISC,
- IFLA_STATS,
- IFLA_COST,
-#define IFLA_COST IFLA_COST
- IFLA_PRIORITY,
-#define IFLA_PRIORITY IFLA_PRIORITY
- IFLA_MASTER,
-#define IFLA_MASTER IFLA_MASTER
- IFLA_WIRELESS, /* Wireless Extension event - see wireless.h */
-#define IFLA_WIRELESS IFLA_WIRELESS
-};
-
-
-#define IFLA_MAX IFLA_WIRELESS
-
-#define IFLA_RTA(r) ((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct ifinfomsg))))
-#define IFLA_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct ifinfomsg))
-
-/* ifi_flags.
-
- IFF_* flags.
-
- The only change is:
- IFF_LOOPBACK, IFF_BROADCAST and IFF_POINTOPOINT are
- more not changeable by user. They describe link media
- characteristics and set by device driver.
-
- Comments:
- - Combination IFF_BROADCAST|IFF_POINTOPOINT is invalid
- - If neither of these three flags are set;
- the interface is NBMA.
-
- - IFF_MULTICAST does not mean anything special:
- multicasts can be used on all not-NBMA links.
- IFF_MULTICAST means that this media uses special encapsulation
- for multicast frames. Apparently, all IFF_POINTOPOINT and
- IFF_BROADCAST devices are able to use multicasts too.
- */
-
-/* IFLA_LINK.
- For usual devices it is equal ifi_index.
- If it is a "virtual interface" (f.e. tunnel), ifi_link
- can point to real physical interface (f.e. for bandwidth calculations),
- or maybe 0, what means, that real media is unknown (usual
- for IPIP tunnels, when route to endpoint is allowed to change)
- */
-
-/*****************************************************************
- * Traffic control messages.
- ****/
-
-struct tcmsg
-{
- unsigned char tcm_family;
- unsigned char tcm__pad1;
- unsigned short tcm__pad2;
- int tcm_ifindex;
- __u32 tcm_handle;
- __u32 tcm_parent;
- __u32 tcm_info;
-};
-
-enum
-{
- TCA_UNSPEC,
- TCA_KIND,
- TCA_OPTIONS,
- TCA_STATS,
- TCA_XSTATS,
- TCA_RATE,
-};
-
-#define TCA_MAX TCA_RATE
-
-#define TCA_RTA(r) ((struct rtattr*)(((char*)(r)) + NLMSG_ALIGN(sizeof(struct tcmsg))))
-#define TCA_PAYLOAD(n) NLMSG_PAYLOAD(n,sizeof(struct tcmsg))
-
-
-/* SUMMARY: maximal rtattr understood by kernel */
-
-#define RTATTR_MAX RTA_MAX
-
-/* RTnetlink multicast groups */
-
-#define RTMGRP_LINK 1
-#define RTMGRP_NOTIFY 2
-#define RTMGRP_NEIGH 4
-#define RTMGRP_TC 8
-
-#define RTMGRP_IPV4_IFADDR 0x10
-#define RTMGRP_IPV4_MROUTE 0x20
-#define RTMGRP_IPV4_ROUTE 0x40
-
-#define RTMGRP_IPV6_IFADDR 0x100
-#define RTMGRP_IPV6_MROUTE 0x200
-#define RTMGRP_IPV6_ROUTE 0x400
-
-#define RTMGRP_DECnet_IFADDR 0x1000
-#define RTMGRP_DECnet_ROUTE 0x4000
-
-/* End of information exported to user level */
-
-#ifdef __KERNEL__
-
-#include <linux/config.h>
-
-static __inline__ int rtattr_strcmp(struct rtattr *rta, char *str)
-{
- int len = strlen(str) + 1;
- return len > rta->rta_len || memcmp(RTA_DATA(rta), str, len);
-}
-
-extern int rtattr_parse(struct rtattr *tb[], int maxattr, struct rtattr *rta, int len);
-
-extern struct sock *rtnl;
-
-struct rtnetlink_link
-{
- int (*doit)(struct sk_buff *, struct nlmsghdr*, void *attr);
- int (*dumpit)(struct sk_buff *, struct netlink_callback *cb);
-};
-
-extern struct rtnetlink_link * rtnetlink_links[NPROTO];
-extern int rtnetlink_dump_ifinfo(struct sk_buff *skb, struct netlink_callback *cb);
-extern int rtnetlink_send(struct sk_buff *skb, u32 pid, u32 group, int echo);
-extern int rtnetlink_put_metrics(struct sk_buff *skb, u32 *metrics);
-
-extern void __rta_fill(struct sk_buff *skb, int attrtype, int attrlen, const void *data);
-
-#define RTA_PUT(skb, attrtype, attrlen, data) \
-({ if (skb_tailroom(skb) < (int)RTA_SPACE(attrlen)) goto rtattr_failure; \
- __rta_fill(skb, attrtype, attrlen, data); })
-
-extern void rtmsg_ifinfo(int type, struct net_device *dev, unsigned change);
-
-extern struct semaphore rtnl_sem;
-
-#define rtnl_exlock() do { } while(0)
-#define rtnl_exunlock() do { } while(0)
-#define rtnl_exlock_nowait() (0)
-
-#define rtnl_shlock() down(&rtnl_sem)
-#define rtnl_shlock_nowait() down_trylock(&rtnl_sem)
-
-#define rtnl_shunlock() do { up(&rtnl_sem); \
- if (rtnl && rtnl->receive_queue.qlen) \
- rtnl->data_ready(rtnl, 0); \
- } while(0)
-
-extern void rtnl_lock(void);
-extern void rtnl_unlock(void);
-extern void rtnetlink_init(void);
-
-#define ASSERT_RTNL() do { if (down_trylock(&rtnl_sem) == 0) { up(&rtnl_sem); \
-printk("RTNL: assertion failed at " __FILE__ "(%d)\n", __LINE__); } \
- } while(0)
-#define BUG_TRAP(x) if (!(x)) { printk("KERNEL: assertion (" #x ") failed at " __FILE__ "(%d)\n", __LINE__); }
-
-
-#endif /* __KERNEL__ */
-
-
-#endif /* __LINUX_RTNETLINK_H */
diff --git a/src/util.c b/src/util.c
index be35f94..df1f836 100644
--- a/src/util.c
+++ b/src/util.c
@@ -29,8 +29,6 @@
#include "util.h"
-struct hw_addr null_ap = { { 0, 0, 0, 0, 0, 0 } };
-
void print_hex(FILE *f, uint8_t *w, int l) {
while (l > 0) {
fprintf(f, "%02x", *(w++));
@@ -38,37 +36,6 @@ void print_hex(FILE *f, uint8_t *w, int l) {
}
}
-int hw_addr_equal(struct hw_addr *a, struct hw_addr *b) {
- return memcmp(a->addr, b->addr, ETH_ALEN) == 0;
-}
-
-int is_assoc_ap(struct hw_addr *ap) {
- int b, j;
- b = 1;
- assert(ap);
-
- for (j = 1; j < ETH_ALEN; j++)
- if (ap->addr[j] != ap->addr[0]) {
- b = 0;
- break;
- }
-
- return !b || (ap->addr[0] != 0xFF && ap->addr[0] != 0x44 && ap->addr[0] != 0x00);
-}
-
-
-void print_hw_addr(FILE*f, struct hw_addr *a) {
- fprintf(f, "%02x:%02x:%02x:%02x:%02x:%02x",
- a->addr[0], a->addr[1], a->addr[2],
- a->addr[3], a->addr[4], a->addr[5]);
-}
-
-void snprint_hw_addr(char *c, int l, struct hw_addr *a) {
- snprintf(c, l, "%02x:%02x:%02x:%02x:%02x:%02x",
- a->addr[0], a->addr[1], a->addr[2],
- a->addr[3], a->addr[4], a->addr[5]);
-}
-
int parse_hex(char *s, uint8_t *b, int l) {
int n = 0;
@@ -108,49 +75,3 @@ int parse_hex(char *s, uint8_t *b, int l) {
}
-int get_ifname(int idx, char *p, int l) {
- struct ifreq req;
- int s;
-
- if ((s = socket(PF_INET, SOCK_DGRAM, 0)) < 0) {
- daemon_log(LOG_ERR, "socket() failed: %s\n", strerror(errno));
- return -1;
- }
-
- memset(&req, 0, sizeof(req));
- req.ifr_ifindex = idx;
-
- if(ioctl(s, SIOCGIFNAME, &req) < 0) {
- close(s);
- daemon_log(LOG_ERR, "SIOCGIFNAME failed: %s\n", strerror(errno));
- return -1;
- }
-
- close(s);
-
- strncpy(p, req.ifr_name, l-1);
- p[l-1] = 0;
-
- return 0;
-}
-
-int is_iface_available(char *p) {
- struct ifreq req;
- int s, r;
-
- if ((s = socket(PF_INET, SOCK_DGRAM, 0)) < 0) {
- daemon_log(LOG_ERR, "socket() failed: %s\n", strerror(errno));
- return -1;
- }
-
- memset(&req, 0, sizeof(req));
- strncpy(req.ifr_name, p, IFNAMSIZ);
-
- if ((r = ioctl(s, SIOCGIFINDEX, &req)) < 0 && errno != ENODEV) {
- daemon_log(LOG_ERR, "SIOCGIFINDEX failed: %s\n", strerror(errno));
- return -1;
- }
-
- close(s);
- return r >= 0 && req.ifr_ifindex >= 0;
-}
diff --git a/src/util.h b/src/util.h
index 956079f..7c5c0c6 100644
--- a/src/util.h
+++ b/src/util.h
@@ -32,19 +32,13 @@
#define MIN(a,b) ((a)<(b)?(a):(b))
#endif
-struct hw_addr {
+/*struct hw_addr {
uint8_t addr[ETH_ALEN];
-};
+ };*/
extern struct hw_addr null_ap;
void print_hex(FILE *f, uint8_t *w, int l);
-void print_hw_addr(FILE*f, struct hw_addr *a);
-void snprint_hw_addr(char *c, int l, struct hw_addr *a);
int parse_hex(char *s, uint8_t *b, int l);
-int hw_addr_equal(struct hw_addr *a, struct hw_addr *b);
-int is_assoc_ap(struct hw_addr *ap);
-int get_ifname(int idx, char *p, int l);
-int is_iface_available(char *p);
#endif
diff --git a/src/wireless.h b/src/wireless.h
index c111ef1..55262ae 100644
--- a/src/wireless.h
+++ b/src/wireless.h
@@ -21,6 +21,10 @@
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*/
+#include <sys/types.h>
+#include <sys/socket.h>
+
+
#include <linux/if.h>
#include "wireless.15.h"