[systemd-devel] [PATCH 1/8] add source format modeline

2013-12-09 Thread Joonas Lahtinen

For easier editing, add source format modeline similar to other files.

Signed-off-by: Joonas Lahtinen 
Reviewed-by: Mikko Ylinen 
Acked-by: Darren Hart 
---
 src/efi/gummiboot.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/efi/gummiboot.c b/src/efi/gummiboot.c
index 8ef3e09..127db22 100644
--- a/src/efi/gummiboot.c
+++ b/src/efi/gummiboot.c
@@ -1,3 +1,5 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
 /*
  * Simple UEFI boot loader which executes configured EFI images, where the
  * default entry is selected by a configured pattern (glob) or an 
on-screen

--
1.8.1.4


___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] [PATCH 4/8] make file_read callable outside compilation unit

2013-12-09 Thread Joonas Lahtinen

Make file_read usable from other compilation units allowing reuse
of code when splitting functionality to multiple files.

Signed-off-by: Joonas Lahtinen 
Reviewed-by: Darren Hart 
Reviewed-by: Mikko Ylinen 
---
 src/efi/gummiboot.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/efi/gummiboot.c b/src/efi/gummiboot.c
index 8a83474..062865d 100644
--- a/src/efi/gummiboot.c
+++ b/src/efi/gummiboot.c
@@ -1621,7 +1621,7 @@ static VOID config_entry_add_from_file(Config 
*config, EFI_HANDLE *device, CHAR1

 config_add_entry(config, entry);
 }
 -static UINTN file_read(EFI_FILE_HANDLE dir, CHAR16 *name, CHAR8 
**content) {

+UINTN file_read(EFI_FILE_HANDLE dir, CHAR16 *name, CHAR8 **content) {
 EFI_FILE_HANDLE handle;
 EFI_FILE_INFO *info;
 CHAR8 *buf;
--
1.8.1.4


___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] [PATCH 3/8] add atoi function

2013-12-09 Thread Joonas Lahtinen

Add generic purpose number parsing function to be used by modeline
parsing.

Signed-off-by: Joonas Lahtinen 
Reviewed-by: Darren Hart 
Reviewed-by: Mikko Ylinen 
---
 src/efi/gummiboot.c | 26 ++
 1 file changed, 26 insertions(+)

diff --git a/src/efi/gummiboot.c b/src/efi/gummiboot.c
index 127db22..8a83474 100644
--- a/src/efi/gummiboot.c
+++ b/src/efi/gummiboot.c
@@ -1356,6 +1356,32 @@ static CHAR8 *strchra(CHAR8 *s, CHAR8 c) {
 return NULL;
 }
 +static INTN atoi(CHAR16  *str)
+{
+INTN   i;
+BOOLEANsign = FALSE;
+CHAR16 c;
+
+while (*str && *str == ' ') {
+str += 1;
+}
+
+if(*str == '-') {
+sign = TRUE;
+str += 1;
+}
+
+i = 0;
+while (c = *(str++)) {
+if (c >= '0' && c <= '9') {
+i = (i * 10) + (c - '0');
+} else {
+break;
+}
+}
+return sign ? -i : i;
+}
+
 static CHAR8 *line_get_key_value(CHAR8 *content, UINTN *pos, CHAR8 
**key_ret, CHAR8 **value_ret) {

 CHAR8 *line;
 UINTN linelen;
--
1.8.1.4


___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] [PATCH 2/8] Makefile.am: be consistent defining sources

2013-12-09 Thread Joonas Lahtinen

Be consistent with other source file definitions.

Signed-off-by: Joonas Lahtinen 
Reviewed-by: Mikko Ylinen 
Acked-by: Darren Hart 
---
 Makefile.am | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/Makefile.am b/Makefile.am
index b32dc76..a17493d 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -73,7 +73,8 @@ CLEANFILES += man/gummiboot.8
 # bypasses regular automake to provide absolute control on compiler 
and linker

 # flags.
 efi_loadername = gummiboot$(MACHINE_TYPE_NAME).efi
-efi_sources = src/efi/gummiboot.c
+efi_sources = \
+   src/efi/gummiboot.c
  efi_cppflags = \
$(EFI_CPPFLAGS) \
--
1.8.1.4


___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] [PATCH 7/8] add ppm2bgrx utility

2013-12-09 Thread Joonas Lahtinen

Add utility to convert 8-bit PPM files into UEFI GOP supported BGRX
files to be used as splash screens.

Signed-off-by: Joonas Lahtinen 
Reviewed-by: Mikko Ylinen 
Acked-by: Darren Hart 
---
 .gitignore   |   1 +
 Makefile.am  |  12 
 README.gop   |  10 +++
 utils/ppm2bgrx.c | 199 
+++

 4 files changed, 222 insertions(+)
 create mode 100644 utils/ppm2bgrx.c

diff --git a/.gitignore b/.gitignore
index 047bb03..c4e337e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -12,6 +12,7 @@
 /gummibootia32.efi
 /gummibootx64.efi
 /test-disk
+/ppm2bgrx
  Makefile
 aclocal.m4
diff --git a/Makefile.am b/Makefile.am
index 7922f00..52486df 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -53,6 +53,18 @@ gummiboot_CFLAGS = \
 gummiboot_LDADD = \
$(BLKID_LIBS)
 +if ENABLE_GOP
+bin_PROGRAMS += ppm2bgrx
+ppm2bgrx_SOURCES = \
+   utils/ppm2bgrx.c
+
+ppm2bgrx_CPPFLAGS = \
+   $(AM_CPPFLAGS)
+
+ppm2bgrx_CFLAGS = \
+   $(AM_CFLAGS)
+endif
+
 if ENABLE_MANPAGES
 %.8: %.xml
$(AM_V_GEN)$(XSLTPROC) -o $@ --nonet \
diff --git a/README.gop b/README.gop
index fef8882..5481b7b 100644
--- a/README.gop
+++ b/README.gop
@@ -44,3 +44,13 @@ Combined with the i915.fastboot patches for detecting 
the BIOS/UEFI initialized
 graphics mode and using weston with --current-mode option you should 
be able to
 keep the graphical splash screen drawn during gummiboot execution to 
stay on the

 screen until the desktop shell is drawn. How cool is that?
+
+CONVERTING SPLASH SCREEN TO SUITABLE FORMAT
+
+To convert your preferred splash screen image to the required BGRX 
format you
+can use the supplied ppm2bgrx program. But first you need to use GIMP 
or some
+other image editing program to convert the image to 8-bit PPM format 
which the
+ppm2bgrx program can understand. After that it is simply a matter of 
running one

+command:
+
+$ ppm2bgrx input.ppm output.bgrx
diff --git a/utils/ppm2bgrx.c b/utils/ppm2bgrx.c
new file mode 100644
index 000..28c9ed1
--- /dev/null
+++ b/utils/ppm2bgrx.c
@@ -0,0 +1,199 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+/*
+ * Simple UEFI boot loader which executes configured EFI images, where the
+ * default entry is selected by a configured pattern (glob) or an on-screen
+ * menu.
+ *
+ * All gummiboot code is LGPL not GPL, to stay out of politics and to give
+ * the freedom of copying code from programs to possible future libraries.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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
+ * Lesser General Public License for more details.
+ *
+ * Copyright (C) 2013 Intel Corporation, EFI GOP parts
+ *Authored by Joonas Lahtinen 
+ *
+ * "Everything should be made as simple as possible, but not simpler."
+ *   -- Albert Einstein
+ */
+
+#include 
+#include 
+#include 
+
+static char* ppm_readline(FILE* stream, int skip_ws) {
+int c, skip;
+size_t i, buf_size;
+char* buf;
+
+/* Guess for initial maximum line size for PPM file headers. */
+buf_size = 32;
+buf = malloc(buf_size);
+if (!buf)
+goto err;
+
+if (skip_ws) {
+do {
+if (ferror(stream))
+goto err2;
+c = fgetc(stream);
+if (c == EOF)
+goto err2;
+} while(strchr(" \t\r\n", c));
+}
+start_line:
+skip = 0;
+i = 0;
++while (!ferror(stream)) {
+if (skip_ws)
+skip_ws = 0;
+else
+c = fgetc(stream);
+
+if (c == EOF)
+break;
+if ((i == 0) && (c == '#'))
+skip = 1;
+if (strchr(skip ? "\r\n" : " \t\r\n", c)) {
+if (skip)
+goto start_line;
+break;
+}
+if (i >= buf_size - 1) {
+buf = realloc(buf, buf_size *= 2);
+if (!buf)
+goto err;
+}
+buf[i++] = c;
+}
+
+if (skip)
+goto err2;
+if (!i)
+goto err;
+buf[i] = 0;
+return buf;
+err2:
+free(buf);
+err:
+return NULL;
+}
+
+int main(int argc, char* argv[]) {
+FILE* input;
+FILE* output;
+char* line;
+int w,h,m

[systemd-devel] [PATCH 5/8] make console_text_mode into more generic function

2013-12-09 Thread Joonas Lahtinen

Convert console_text_mode function into console_mode function
which is able to switch back and forth between graphics and text
mode.

Signed-off-by: Joonas Lahtinen 
Reviewed-by: Darren Hart 
Reviewed-by: Mikko Ylinen 
---
 src/efi/gummiboot.c | 32 +---
 1 file changed, 29 insertions(+), 3 deletions(-)

diff --git a/src/efi/gummiboot.c b/src/efi/gummiboot.c
index 062865d..6c66f63 100644
--- a/src/efi/gummiboot.c
+++ b/src/efi/gummiboot.c
@@ -54,6 +54,11 @@ enum loader_type {
 LOADER_LINUX
 };
 +enum console_mode {
+CONSOLE_TEXT,
+CONSOLE_GRAPHICS,
+};
+
 typedef struct {
 CHAR16 *file;
 CHAR16 *title_show;
@@ -736,7 +741,7 @@ static VOID print_status(Config *config, CHAR16 
*loaded_image_path) {

 uefi_call_wrapper(ST->ConOut->ClearScreen, 1, ST->ConOut);
 }
 -static EFI_STATUS console_text_mode(VOID) {
+static EFI_STATUS console_mode(enum console_mode request) {
 #define EFI_CONSOLE_CONTROL_PROTOCOL_GUID \
 { 0xf42f7782, 0x12e, 0x4c12, { 0x99, 0x56, 0x49, 0xf9, 
0x43, 0x4, 0xf7, 0x21 } };

 @@ -773,12 +778,33 @@ static EFI_STATUS console_text_mode(VOID) {
  EFI_GUID ConsoleControlProtocolGuid = 
EFI_CONSOLE_CONTROL_PROTOCOL_GUID;

 EFI_CONSOLE_CONTROL_PROTOCOL *ConsoleControl = NULL;
+EFI_CONSOLE_CONTROL_SCREEN_MODE new;
+EFI_CONSOLE_CONTROL_SCREEN_MODE current;
+BOOLEAN uga_exists;
+BOOLEAN stdin_locked;
 EFI_STATUS err;
  err = LibLocateProtocol(&ConsoleControlProtocolGuid, (VOID 
**)&ConsoleControl);

 if (EFI_ERROR(err))
 return err;
-return uefi_call_wrapper(ConsoleControl->SetMode, 2, 
ConsoleControl, EfiConsoleControlScreenText);

+
+/* be extra cautious about not causing mode switch */
+err = uefi_call_wrapper(ConsoleControl->GetMode, 4, 
ConsoleControl, ¤t, &uga_exists, &stdin_locked);

+if (err == EFI_SUCCESS) {
+switch (request) {
+case CONSOLE_GRAPHICS:
+new = EfiConsoleControlScreenGraphics;
+break;
+case CONSOLE_TEXT:
+new = EfiConsoleControlScreenText;
+break;
+}
+
+if (new == current)
+return EFI_SUCCESS;
+}
+
+return uefi_call_wrapper(ConsoleControl->SetMode, 2, 
ConsoleControl, new);

 }
  static BOOLEAN menu_run(Config *config, ConfigEntry **chosen_entry, 
CHAR16 *loaded_image_path) {
@@ -805,7 +831,7 @@ static BOOLEAN menu_run(Config *config, ConfigEntry 
**chosen_entry, CHAR16 *load

 BOOLEAN run = TRUE;
 BOOLEAN wait = FALSE;
 -console_text_mode();
+console_mode(CONSOLE_TEXT);
 uefi_call_wrapper(ST->ConIn->Reset, 2, ST->ConIn, FALSE);
 uefi_call_wrapper(ST->ConOut->EnableCursor, 2, ST->ConOut, FALSE);
 uefi_call_wrapper(ST->ConOut->SetAttribute, 2, ST->ConOut, 
EFI_LIGHTGRAY|EFI_BACKGROUND_BLACK);

--
1.8.1.4


___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] [PATCH 0/8] GOP display initialization and splash screen drawing

2013-12-09 Thread Joonas Lahtinen

Hi,

The following patch series implement UEFI GOP graphics mode
initialization and screen clearing functionality to Gummiboot. They're
all based on top of the current master. The functionality was written
against the UEFI specification, so it should work everywhere where that
functionality is available.

More details about the functionality added is in README.gop file added
in patch 6/8.

For anyone interested, at the time of sending these patches the patches
for i915.fastboot features mentioned in the README.gop file are on their
way to upstream and can be found at:

git://people.freedesktop.org/~jbarnes/linux

on branch inherit-bios .

Would be great to have these applied to master, they've already been
tested on a few modern UEFI implementation and are working. Currently
this work is made to be used by Tizen IVI project.

Regards, Joonas

--
 .gitignore  |   1 +
 Makefile.am |  28 +-
 README.gop  |  56 
 configure.ac|   7 ++
 data/gummiboot.ppm  | Bin 0 -> 196662 bytes
 src/efi/gop.c   | 137 +
 src/efi/gop.h   |  48 ++
 src/efi/gummiboot.c | 160 +-
 utils/ppm2bgrx.c| 208 
 9 files changed, 640 insertions(+), 5 deletions(-)

--
Joonas Lahtinen
Intel Open Source Technology Center

___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] [PATCH 6/8] add GOP mode setting and splash drawing support

2013-12-09 Thread Joonas Lahtinen

Add support for two new configuration directives gfxmode and splash
which respectively allow setting the screen graphics mode and drawing
splash image during gummiboot execution. See README.gop for more
details.

Signed-off-by: Joonas Lahtinen 
Reviewed-by: Mikko Ylinen 
Acked-by: Darren Hart 
---
 Makefile.am |   5 ++
 README.gop  |  46 ++
 configure.ac|   7 +++
 src/efi/gop.c   | 137 


 src/efi/gop.h   |  48 ++
 src/efi/gummiboot.c | 100 +-
 6 files changed, 342 insertions(+), 1 deletion(-)
 create mode 100644 README.gop
 create mode 100644 src/efi/gop.c
 create mode 100644 src/efi/gop.h

diff --git a/Makefile.am b/Makefile.am
index a17493d..7922f00 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -76,6 +76,11 @@ efi_loadername = gummiboot$(MACHINE_TYPE_NAME).efi
 efi_sources = \
src/efi/gummiboot.c
 +if ENABLE_GOP
+efi_sources += \
+   src/efi/gop.c
+endif
+
 efi_cppflags = \
$(EFI_CPPFLAGS) \
-I$(top_builddir) -include config.h \
diff --git a/README.gop b/README.gop
new file mode 100644
index 000..fef8882
--- /dev/null
+++ b/README.gop
@@ -0,0 +1,46 @@
+WHAT IS GOP USEFUL FOR?
+
+Using UEFI GOP (Graphics Output Protocol) allows gummiboot to draw splash
+screen instantly after UEFI firmware has finished. This should give the 
user a

+instant on feeling instead of just seeing a black screen during the boot.
+
+ENABLING MODE SETTING AND SPLASH SCREEN DRAWING
+
+The GOP features, display mode setting and splash drawing, can be 
enabled +globally or per entry by adding a configuration keyword to the 
respective

+configuration file.
+
+Graphics mode can be attempted to be set with the following line:
+
+   gfxmode 1920x1080
+
+This would attempt to use the GOP protocol to set certain resolution to the
+screen, FullHD in this case.
+
+Splash screen can be drawn to the screen with the following directive:
+
+   splash /splash.bgrx
+
+This would attempt to draw a splash screen from a file named "splash.bgrx"
+located in the EFI System Partition root directory. The file needs to be
+properly encoded into BGRX format which is described below. If the splash
+screen resolution is less than the active screen resolution, the image will
+be drawn centered vertically and horizontally.
+
+BGRX FORMAT
+
+The file format is extremely simple. BGRX file can be identified by the 
first
+four bytes which are "BGRX" in ASCII encoding. The full format is as 
follows:

+
+4-byte  Header (should be "BGRX")
+2-byte  Width as 16-bit unsigned integer stored in MSB
+2-byte  Height as 16-bit unsigned integer stored in MSB
+[w*h*4-byte]   Multiple pixels each with 1-byte for B, G, R and X channels in
+order, where X is discarded.
+
+EXTRA FOR INTEL I915 GRAPHICS
+
+Combined with the i915.fastboot patches for detecting the BIOS/UEFI 
initialized
+graphics mode and using weston with --current-mode option you should be 
able to
+keep the graphical splash screen drawn during gummiboot execution to 
stay on the

+screen until the desktop shell is drawn. How cool is that?
diff --git a/configure.ac b/configure.ac
index f8ce22b..6bf62fa 100644
--- a/configure.ac
+++ b/configure.ac
@@ -131,6 +131,12 @@ AS_IF([test "x$enable_manpages" != xno], [
 AM_CONDITIONAL(ENABLE_MANPAGES, [test "x$have_manpages" = "xyes"])
  # 
--
+AC_ARG_ENABLE(gop, AS_HELP_STRING([--enable-gop], [enable GOP mode 
setting and bootsplash]), enable_gop=yes, enable_gop=no)

+AM_CONDITIONAL(ENABLE_GOP, [test "x$enable_gop" = "xyes"])
+AH_TEMPLATE([ENABLE_GOP], [Define to enable support for GOP mode 
setting and bootsplash.])

+AS_IF([test "x$enable_gop" = "xyes"], [AC_DEFINE([ENABLE_GOP], [1])])
+
+# 
--

 AC_CONFIG_FILES([
 Makefile
 ])
@@ -142,6 +148,7 @@ AC_MSG_RESULT([
 prefix:  ${prefix}
 arch:$ARCH
 EFI machine type:$MACHINE_TYPE_NAME
+GOP: ${enable_gop}
  EFI libdir:  ${EFI_LIB_DIR}
 EFI ldsdir:  ${EFI_LDS_DIR}
diff --git a/src/efi/gop.c b/src/efi/gop.c
new file mode 100644
index 000..1e5
--- /dev/null
+++ b/src/efi/gop.c
@@ -0,0 +1,137 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+/*
+ * Simple UEFI boot loader which executes configured EFI images, where the
+ * default entry is selected by a configured pattern (glob) or an on-screen
+ * menu.
+ *
+ * All gummiboot code is LGPL not GPL, to stay out of politics and to give
+ * the freedom of copying code from programs to possible future libraries.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser Genera

Re: [systemd-devel] udevadm settle takes too long to finish

2013-12-09 Thread Cristian Rodríguez

El 10/12/13 03:47, Andrey Borzenkov escribió:


There is no such service on openSUSE, which OP has :)


Yes there is :-) but in factory only.

___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] udevadm settle takes too long to finish

2013-12-09 Thread Andrey Borzenkov
В Mon, 9 Dec 2013 12:42:21 -0700
Chris Murphy  пишет:

> 
> On Dec 9, 2013, at 3:33 AM, Thomas Bächler  wrote:
> 
> > Am 07.12.2013 22:29, schrieb Robert Milasan:
> >> From systemd-analyze dump:
> >> 
> >>Wants: systemd-udevd.service
> >>WantedBy: lvm2-activation-early.service
> >>WantedBy: lvm2-activation.service
> >>Before: lvm2-activation-early.service
> >>Before: sysinit.target
> >>After: systemd-udev-trigger.service
> >>After: systemd-journald.socket
> >>References: systemd-udevd.service
> >>References: systemd-udev-trigger.service
> >>References: sysinit.target
> >>References: systemd-journald.socket
> >>ReferencedBy: lvm2-activation-early.service
> >>ReferencedBy: lvm2-activation.service
> > 
> > What's the distribution you are using? Using udevadm settle for lvm is a
> > waste of boot time and isn't even guaranteed to work (ask Lennart, Kay
> > or Greg K-H for the full speech). It's a hackish workaround for LVM's
> > inability to activate volumes automatically.
> 
> I'm finding that plymouth-start.service uses ExecStartPost= to call udevadm 
> settle twice.
> 
> The actual culprit though is dmraid-activation.service which is enabled by 
> default (why?) and Wants=systemd-udev-settle.service. 
> dmraid.activation.service also has the #2 biggest blame hit:
> 4.551s dmraid-activation.service
> 

There is no such service on openSUSE, which OP has :)

> So why is this enabled by default when there's no dmraid at all, and never 
> has been dmraid metadata on any attached device?
> 

The obvious question is - and how should system know it? Who is
responsible for activating it again after you have added dmraid devices?

Is it possible to trigger dmraid from some udev rule similar to what
mdadm currently does?

> If I systemctl disable dmraid-activation.service both the 
> dmraid-activation.service hit goes away, as does systemd-udev-settle.service.
> 
> 
> Chris Murphy
> ___
> systemd-devel mailing list
> systemd-devel@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/systemd-devel

___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] [PATCH] fix scan-build issues

2013-12-09 Thread Zbigniew Jędrzejewski-Szmek
On Mon, Dec 09, 2013 at 09:01:08PM +0100, Thomas H.P. Andersen wrote:
> From: Thomas Hindoe Paaboel Andersen 
> 
> The static analyzer scan-build had a few issues with analysing
> parts of systemd.
> 
> gpt-auto-generator.c:
> scan-build could not find blkid.h. Whether it should be blkid.h or
> blkid/blkid.h seems to depend on the version used. We already use
> blkid/blkid.h in udev-builtin-blkid.c so it seems safe to use that
> here too.
Looks reasonable.

> Makefile.am:
> Moved some -D's from CFLAGS to CPPFLAGS. I also simplified them a
> bit and got rid of a left over DBUS_CFLAGS.
I think that this breaks compilation if the directory has
spaces in the name. Not a big deal, but as a matter of principle
we should do it right. I think that

-DTEST_DIR='"$(top_srcdir)/test"' should work. 

(We also don't need "top_", because almost everything is done from
the same srcdir, udev docs being the exeption).

Zbyszek

> ---
>  Makefile.am | 22 --
>  src/gpt-auto-generator/gpt-auto-generator.c |  2 +-
>  2 files changed, 13 insertions(+), 11 deletions(-)
> 
> diff --git a/Makefile.am b/Makefile.am
> index 7bedd76..e90e7ed 100644
> --- a/Makefile.am
> +++ b/Makefile.am
> @@ -1349,10 +1349,9 @@ test_cgroup_LDADD = \
>  test_cgroup_mask_SOURCES = \
>   src/test/test-cgroup-mask.c
>  
> -test_cgroup_mask_CFLAGS = \
> - $(AM_CFLAGS) \
> - $(DBUS_CFLAGS) \
> - -D"STR(s)=\#s" -D"TEST_DIR=STR($(abs_top_srcdir)/test/)"
> +test_cgroup_mask_CPPFLAGS = \
> + $(AM_CPPFLAGS) \
> + -DTEST_DIR=\"$(abs_top_srcdir)/test\"
>  
>  test_cgroup_mask_LDADD = \
>   libsystemd-core.la \
> @@ -1416,9 +1415,9 @@ test_watchdog_LDADD = \
>  test_sched_prio_SOURCES = \
>   src/test/test-sched-prio.c
>  
> -test_sched_prio_CFLAGS = \
> - $(AM_CFLAGS) \
> - -D"STR(s)=\#s" -D"TEST_DIR=STR($(abs_top_srcdir)/test/)"
> +test_sched_prio_CPPFLAGS = \
> + $(AM_CPPFLAGS) \
> + -DTEST_DIR=\"$(abs_top_srcdir)/test\"
>  
>  test_sched_prio_LDADD = \
>   libsystemd-core.la \
> @@ -3054,8 +3053,8 @@ test_mmap_cache_LDADD = \
>  test_catalog_SOURCES = \
>   src/journal/test-catalog.c
>  
> -test_catalog_CFLAGS = \
> - $(AM_CFLAGS) \
> +test_catalog_CPPFLAGS = \
> + $(AM_CPPFLAGS) \
>   -DCATALOG_DIR=\"$(abs_top_srcdir)/catalog\"
>  
>  test_catalog_LDADD = \
> @@ -3313,9 +3312,12 @@ systemd_journal_gatewayd_LDADD = \
>  
>  systemd_journal_gatewayd_CFLAGS = \
>   $(AM_CFLAGS) \
> - -DDOCUMENT_ROOT=\"$(gatewayddocumentrootdir)\" \
>   $(MICROHTTPD_CFLAGS)
>  
> +systemd_journal_gatewayd_CPPFLAGS = \
> + $(AM_CPPFLAGS) \
> + -DDOCUMENT_ROOT=\"$(gatewayddocumentrootdir)\"
> +
>  dist_systemunit_DATA += \
>   units/systemd-journal-gatewayd.socket
>  
> diff --git a/src/gpt-auto-generator/gpt-auto-generator.c 
> b/src/gpt-auto-generator/gpt-auto-generator.c
> index 3cbafa4..017c35d 100644
> --- a/src/gpt-auto-generator/gpt-auto-generator.c
> +++ b/src/gpt-auto-generator/gpt-auto-generator.c
> @@ -24,7 +24,7 @@
>  #include 
>  #include 
>  #include 
> -#include 
> +#include 
>  
>  #ifdef HAVE_LINUX_BTRFS_H
>  #include 
> -- 
> 1.8.4.2
> 
> ___
> systemd-devel mailing list
> systemd-devel@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/systemd-devel
> 
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] [PATCH] libsystemd-bus: Clean up code

2013-12-09 Thread Zbigniew Jędrzejewski-Szmek
On Mon, Dec 09, 2013 at 09:22:43PM +0100, Thomas H.P. Andersen wrote:
> If I understood correctly then the assert_return was meant to be used
> only on the public library functions. I can't seem to find the
> reference to it so maybe I am wrong though.
There's no strong reason to limit usage to public functions. It's just
a simple macro really.

> On Mon, Dec 9, 2013 at 2:09 PM, Lukasz Skalski
>  wrote:
> > ---
> >  src/libsystemd-bus/bus-dump.c  |  2 +-
> >  src/libsystemd-bus/bus-error.c |  3 +--
> >  src/libsystemd-bus/bus-kernel.c| 12 +++-
> >  src/libsystemd-bus/bus-message.c   | 12 +++-
> >  src/libsystemd-bus/bus-signature.c | 13 -
> >  5 files changed, 12 insertions(+), 30 deletions(-)
> >
> > diff --git a/src/libsystemd-bus/bus-dump.c b/src/libsystemd-bus/bus-dump.c
> > index ddad418..a999683 100644
> > --- a/src/libsystemd-bus/bus-dump.c
> > +++ b/src/libsystemd-bus/bus-dump.c
> > @@ -56,7 +56,7 @@ int bus_message_dump(sd_bus_message *m, FILE *f, bool 
> > with_header) {
> >
> >  if (with_header) {
> >  fprintf(f,
> > -"%s%s%sType=%s%s%s  Endian=%c  Flags=%u  
> > Version=%u",
> > +"%s%s%sType=%s%s%s  Endian=%c  Flags=%u  
> > Version=%u ",
I don't get this part, since a space is added in the messages right below.

> >  m->header->type == SD_BUS_MESSAGE_METHOD_ERROR ? 
> > ansi_highlight_red() :
> >  m->header->type == SD_BUS_MESSAGE_METHOD_RETURN ? 
> > ansi_highlight_green() :
> >  m->header->type != SD_BUS_MESSAGE_SIGNAL ? 
> > ansi_highlight() : "", draw_special_char(DRAW_TRIANGULAR_BULLET), 
> > ansi_highlight_off(),
> > diff --git a/src/libsystemd-bus/bus-error.c b/src/libsystemd-bus/bus-error.c
> > index 25eaf0e..4f18629 100644
> > --- a/src/libsystemd-bus/bus-error.c
> > +++ b/src/libsystemd-bus/bus-error.c
> > @@ -39,8 +39,7 @@ static int bus_error_name_to_errno(const char *name) {
> >  const char *p;
> >  int r;
> >
> > -if (!name)
> > -return EINVAL;
> > +assert_return(name, EINVAL);
> >
> >  p = startswith(name, "System.Error.");
> >  if (p) {
> > diff --git a/src/libsystemd-bus/bus-kernel.c 
> > b/src/libsystemd-bus/bus-kernel.c
> > index 495d7e5..d5574ce 100644
> > --- a/src/libsystemd-bus/bus-kernel.c
> > +++ b/src/libsystemd-bus/bus-kernel.c
> > @@ -321,9 +321,7 @@ int bus_kernel_take_fd(sd_bus *b) {
> >  int r;
> >
> >  assert(b);
> > -
> > -if (b->is_server)
> > -return -EINVAL;
> > +assert_return(!b->is_server, -EINVAL);
> >
> >  b->use_memfd = 1;
> >
> > @@ -374,9 +372,7 @@ int bus_kernel_connect(sd_bus *b) {
> >  assert(b->input_fd < 0);
> >  assert(b->output_fd < 0);
> >  assert(b->kernel);
> > -
> > -if (b->is_server)
> > -return -EINVAL;
> > +assert_return(!b->is_server, -EINVAL);
> >
> >  b->input_fd = open(b->kernel, O_RDWR|O_NOCTTY|O_CLOEXEC);
> >  if (b->input_fd < 0)
> > @@ -904,9 +900,7 @@ int bus_kernel_pop_memfd(sd_bus *bus, void **address, 
> > size_t *size) {
> >
> >  assert(address);
> >  assert(size);
> > -
> > -if (!bus || !bus->is_kernel)
> > -return -ENOTSUP;
> > +assert_return(bus || bus->is_kernel, -ENOTSUP);
> You should && them here.
Good catch. Fixed up and applied.

Zbyszek
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] [PATCH] Fix usage of kernel-install

2013-12-09 Thread Zbigniew Jędrzejewski-Szmek
On Tue, Dec 10, 2013 at 02:06:07AM +0100, Sébastien Luttringer wrote:
> On 05/12/2013 02:55, Sébastien Luttringer wrote:
> > Kernel install doesn't need the second argument on his command line when
> > removing.
> > This is correctly documented in the man page.
> > 
> > Signed-off-by: Sébastien Luttringer 
> > ---
> >  src/kernel-install/kernel-install | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/src/kernel-install/kernel-install 
> > b/src/kernel-install/kernel-install
> > index 9d3e75d..55cdd69 100644
> > --- a/src/kernel-install/kernel-install
> > +++ b/src/kernel-install/kernel-install
> > @@ -23,7 +23,7 @@ usage()
> >  {
> >  echo "Usage:" >&2
> >  echo "$0 add  " >&2
> > -echo "$0 remove  " >&2
> > +echo "$0 remove " >&2
> >  }
> >  
> >  dropindirs_sort()
> > 
> I know it's a tiny patch, but someone can look at it and with luck,
> merge it?
Sure, applied (after updating to latest git, and dropping the signed-off-by, 
and rewording
the title :)).

Zbyszek
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] [PATCH v3 00/26] Initial DHCP v4 library implementation

2013-12-09 Thread Zbigniew Jędrzejewski-Szmek
On Mon, Dec 09, 2013 at 11:43:06PM +0200, Patrik Flykt wrote:
>   Hi,
> 
> Here is version 3 fixed according to comments plus a few identical ones
> found in the code.
> 
> Essential changes are unconditionally compiling the DHCP code and re-adding
> the sd_dhcp_client_get_netmask() function due to popular demand. Prefix
> length computation is turned into a support function instead.
> 
> The timer problem was solved, the timer callback function gets the supplied
> timeout value, in this case zero, and thus it miscalculated any further
> timer values causing them all to trigger "immediately".
> 
> A proper directory should be selected for the code, currently it's still
> the same old src/dhcp.
If it is to be exported, it should be src/libsystemd-dhcp for
consistency with libsystemd-{bus,daemon,id128,rtnl}. I think we should
merge those patches now, and get networkd with dhcp working.

Zbyszek
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] [PATCH] test: rework run_qemu

2013-12-09 Thread Tom Gundersen
On 10 Dec 2013 02:44, "Ronny Chevalier"  wrote:
>
> Do we really want to add a compat for several distributions ? Because
> why not Archlinux, Ubuntu,... too ?
> I used Fedora's path by default because it was in the previous script.

Maybe just use the path created by our kernel-install script?

Cheers,

Tom

> 2013/12/8 Shawn Landden :
> > On Sat, Dec 7, 2013 at 3:01 PM, Ronny Chevalier
> >  wrote:
> >> It tries to find a suitable QEMU binary and will use KVM if present.
> >> We can now configure QEMU from outside with 4 variables :
> >>   - $QEMU_BIN : path to QEMU's binary
> >>   - $KERNEL_APPEND : arguments appended to kernel cmdline
> >>   - $KERNEL_BIN : path to a kernel
> >> Default /boot/vmlinuz-$KERNEL_VER
> >>   - $INITRD : path to an initramfs
> >> Default /boot/initramfs-${KERNEL_VER}.img
> >>   - $QEMU_SMP : number of CPU simulated by QEMU.
> >> Default 1
> >>
> >> (from Alexander Graf's script:
http://www.spinics.net/lists/kvm/msg72389.html)
> >> ---
> >>  TODO|  1 -
> >>  test/README.testsuite   | 19 ++--
> >>  test/TEST-01-BASIC/test.sh  |  8 ++---
> >>  test/TEST-02-CRYPTSETUP/test.sh |  8 ++---
> >>  test/TEST-03-JOBS/test.sh   |  8 ++---
> >>  test/test-functions | 65
+++--
> >>  6 files changed, 78 insertions(+), 31 deletions(-)
> >>
> >> diff --git a/TODO b/TODO
> >> index 9698082..f493dbb 100644
> >> --- a/TODO
> >> +++ b/TODO
> >> @@ -168,7 +168,6 @@ Features:
> >>  * test/:
> >>- add 'set -e' to scripts in test/
> >>- make stuff in test/ work with separate output dir
> >> -  - qemu wrapper script:
http://www.spinics.net/lists/kvm/msg72389.html
> >>
> >>  * systemctl delete x.snapshot leaves no trace in logs (at least at
default level).
> >>
> >> diff --git a/test/README.testsuite b/test/README.testsuite
> >> index 54d0eaa..2ae85a2 100644
> >> --- a/test/README.testsuite
> >> +++ b/test/README.testsuite
> >> @@ -25,11 +25,24 @@ $ make all
> >>  $ cd test/TEST-01-BASIC
> >>  $ sudo make clean setup run
> >>
> >> +QEMU
> >> +
> >> +
> >>  If you want to log in the testsuite virtual machine, you can specify
> >> -additional kernel command line parameter with $DEBUGFAIL.
> >> +additional kernel command line parameter with $KERNEL_APPEND.
> >>
> >> -$ sudo make DEBUGFAIL="systemd.unit=multi-user.target" clean setup run
> >> +$ sudo make KERNEL_APPEND="systemd.unit=multi-user.target" clean
setup run
> >>
> >>  you can even skip the "clean" and "setup" if you want to run the
machine again.
> >>
> >> -$ sudo make DEBUGFAIL="systemd.unit=multi-user.target" run
> >> +$ sudo make KERNEL_APPEND="systemd.unit=multi-user.target" run
> >> +
> >> +You can specify a different kernel and initramfs with $KERNEL_BIN and
$INITRD.
> >> +(Fedora's default kernel path and initramfs are used by default)
> >> +
> >> +$ sudo make KERNEL_BIN=/boot/vmlinuz-foo INITRD=/boot/initramfs-bar
clean check
> >> +
> >> +A script will try to find your QEMU binary. If you want to specify a
different
> >> +one you can use $QEMU_BIN.
> >> +
> >> +$ sudo make QEMU_BIN=/path/to/qemu/qemu-kvm clean check
> >> diff --git a/test/TEST-01-BASIC/test.sh b/test/TEST-01-BASIC/test.sh
> >> index aaf63f4..84ccf26 100755
> >> --- a/test/TEST-01-BASIC/test.sh
> >> +++ b/test/TEST-01-BASIC/test.sh
> >> @@ -5,9 +5,6 @@ TEST_DESCRIPTION="Basic systemd setup"
> >>
> >>  . $TEST_BASE_DIR/test-functions
> >>
> >> -# Uncomment this to debug failures
> >> -#DEBUGFAIL="systemd.unit=multi-user.target"
> >> -
> >>  check_result_qemu() {
> >>  ret=1
> >>  mkdir -p $TESTDIR/root
> >> @@ -23,11 +20,10 @@ check_result_qemu() {
> >>  }
> >>
> >>  test_run() {
> >> -if check_qemu ; then
> >> -run_qemu
> >> +if run_qemu; then
> >>  check_result_qemu || return 1
> >>  else
> >> -dwarn "can't run qemu-kvm, skipping"
> >> +dwarn "can't run QEMU, skipping"
> >>  fi
> >>  if check_nspawn; then
> >>  run_nspawn
> >> diff --git a/test/TEST-02-CRYPTSETUP/test.sh
b/test/TEST-02-CRYPTSETUP/test.sh
> >> index 86617df..d7e8776 100755
> >> --- a/test/TEST-02-CRYPTSETUP/test.sh
> >> +++ b/test/TEST-02-CRYPTSETUP/test.sh
> >> @@ -5,9 +5,6 @@ TEST_DESCRIPTION="cryptsetup systemd setup"
> >>
> >>  . $TEST_BASE_DIR/test-functions
> >>
> >> -# Uncomment this to debug failures
> >> -#DEBUGFAIL="systemd.unit=multi-user.target"
> >> -
> >>  check_result_qemu() {
> >>  ret=1
> >>  mkdir -p $TESTDIR/root
> >> @@ -28,11 +25,10 @@ check_result_qemu() {
> >>
> >>
> >>  test_run() {
> >> -if check_qemu ; then
> >> -run_qemu
> >> +if run_qemu; then
> >>  check_result_qemu || return 1
> >>  else
> >> -dwarn "can't run qemu-kvm, skipping"
> >> +dwarn "can't run QEMU, skipping"
> >>  fi
> >>  return 0
> >>  }
> >> diff --git a/test/TEST-03-JOBS/test.sh b/test/TEST-03-JOBS/test.sh
> >> index 6303258..41e02e2 100755
> >> --- a/test/TEST-03-JO

Re: [systemd-devel] [PATCH v3 01/26] dhcp: Add DHCP protocol structures and initial defines

2013-12-09 Thread Lennart Poettering
On Mon, 09.12.13 23:43, Patrik Flykt (patrik.fl...@linux.intel.com) wrote:

> +struct DHCPMessage {
> +uint8_t op;
> +uint8_t htype;
> +uint8_t hlen;
> +uint8_t hops;
> +be32_t xid;
> +be16_t secs;
> +be16_t flags;
> +uint32_t ciaddr;
> +uint32_t yiaddr;
> +uint32_t siaddr;
> +uint32_t giaddr;

Hmmm, why uin32_t? Shouldn't this be32_t? THis is network byte order,
right? which is just synoymous to big endian...

Or even, if you now use "struct in_addr" elsewhere anyway, why not just
use that here too?

Lennart

-- 
Lennart Poettering, Red Hat
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] [PATCH v2 00/26] Initial DHCP v4 library implementation

2013-12-09 Thread Lennart Poettering
On Mon, 09.12.13 23:41, Patrik Flykt (patrik.fl...@linux.intel.com) wrote:

> 
> On Mon, 2013-11-25 at 23:52 +0100, Lennart Poettering wrote:
> > Of course, timer callbacks should only be called once, ence
> > ONESHOT mode is the default -- unless you change that explicitly.
> > 
> > If this doesn't solve the issue, I wouldn't be surprised if there was
> > still a bug lurking with the sd-event code. Note that I fixed a bug
> > like this last week, did you check with currentl git of sd-event if
> > the issue persists?
> 
> Found the source of this issue. When the (monotonic) timeout function is
> called with time 0 meaning "immediately", the callback indeed gets
> called next by the event loop. But the uint64_t usec value passed to the
> timer callback is the value 0 set by the caller, not the current
> monotonic time the callback is called at. 

Yes, this is intended that way, so that for periodic usecases dispatch
latencies don't add up. Of course, in your case having the actual time
around is much more desirable.

> Using the supplied usec value,
> which is 0, as a base when calculating the next event timeout results of
> course in a time very much smaller time than the current monotonic time,
> causing the callback to be called immediately again. The value is again
> the one set by the caller and thus the calculated time is again too low.
> Rinse and repeat.
> 
> I fixed the problem by using sd_event_get_now_monotonic() instead of the
> supplied usec value as it wasn't clear what the intended behavior was.
> systemd upstream version tested was from approximately last Friday
> should something have changed recently.

Yes, sd_event_get_now_monotonic() is the right call to use here. It will
return the monotonic time of the current event loop
iteration. Alternatively you could just use now(CLOCK_MONTONIC), but
using sd_event_get_now_monotonic() helps to suppress a syscall...

Lennart

-- 
Lennart Poettering, Red Hat
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] [PATCH] Fix usage of kernel-install

2013-12-09 Thread Sébastien Luttringer
On 05/12/2013 02:55, Sébastien Luttringer wrote:
> Kernel install doesn't need the second argument on his command line when
> removing.
> This is correctly documented in the man page.
> 
> Signed-off-by: Sébastien Luttringer 
> ---
>  src/kernel-install/kernel-install | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/src/kernel-install/kernel-install 
> b/src/kernel-install/kernel-install
> index 9d3e75d..55cdd69 100644
> --- a/src/kernel-install/kernel-install
> +++ b/src/kernel-install/kernel-install
> @@ -23,7 +23,7 @@ usage()
>  {
>  echo "Usage:" >&2
>  echo "$0 add  " >&2
> -echo "$0 remove  " >&2
> +echo "$0 remove " >&2
>  }
>  
>  dropindirs_sort()
> 
I know it's a tiny patch, but someone can look at it and with luck,
merge it?

Cheers,

-- 
Sébastien "Seblu" Luttringer
https://www.seblu.net
GPG: 0x2072D77A



signature.asc
Description: OpenPGP digital signature
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] File system gets remounted read-only after using nspawn

2013-12-09 Thread Canek Peláez Valdés
(Sorry for taking so long to answer, I was away from my test system).

On Sat, Dec 7, 2013 at 5:56 PM, Colin Guthrie  wrote:
> 'Twas brillig, and Canek Peláez Valdés at 05/12/13 23:26 did gyre and
> gimble:
>> Hi; I've been playing with systemd-nspawn with Gentoo. I'm running
>> systemd 208, and the normal Gentoo stage3 image [1], installing
>> systemd 204 inside it. Everything works great, but for some reason
>> after powering off the container, the file system where it resides
>> gets remounted read-only. I should notice that this is a file system
>> different from /.
>
> Interesting. Can't say I've seen this personally. Only thing I've seen
> that is even semi related is that when playing with containers recently,
> the service inside the container that remounts root filesystem rw
> failed. Not seem much else other than that tho'.

I don't think that's the problem; I don't see any error message when
starting or shutting down the container:

centurion ~ # systemd-nspawn -bD /files/gentoo
Spawning namespace container on /files/gentoo (console is /dev/pts/9).
Init process in the container running as PID 2841.
systemd 204 running in system mode. (+PAM +LIBWRAP -AUDIT -SELINUX
+IMA -SYSVINIT -LIBCRYPTSETUP -GCRYPT +ACL -XZ)
Detected virtualization 'systemd-nspawn'.

Welcome to Gentoo/Linux!

[  OK  ] Reached target Remote File Systems.
[  OK  ] Listening on Delayed Shutdown Socket.
[  OK  ] Listening on /dev/initctl Compatibility Named Pipe.
[  OK  ] Reached target Paths.
[  OK  ] Listening on Journal Socket.
 Mounting Huge Pages File System...
 Mounting Debug File System...
 Mounting POSIX Message Queue File System...
 Mounting FUSE Control File System...
 Starting Journal Service...
[  OK  ] Started Journal Service.
[  OK  ] Reached target Swap.
 Starting Remount Root and Kernel File Systems...
 Mounting Temporary Directory...
[  OK  ] Started Remount Root and Kernel File Systems.
[  OK  ] Reached target Local File Systems (Pre).
 Starting Load Random Seed...
[  OK  ] Mounted Temporary Directory.
[  OK  ] Reached target Local File Systems.
 Starting Recreate Volatile Files and Directories...
 Starting Trigger Flushing of Journal to Persistent Storage...
[  OK  ] Mounted POSIX Message Queue File System.
[  OK  ] Mounted Debug File System.
[  OK  ] Mounted Huge Pages File System.
[  OK  ] Mounted FUSE Control File System.
[  OK  ] Started Load Random Seed.
[  OK  ] Started Trigger Flushing of Journal to Persistent Storage.
[  OK  ] Started Recreate Volatile Files and Directories.
[  OK  ] Reached target System Initialization.
[  OK  ] Reached target Timers.
[  OK  ] Listening on D-Bus System Message Bus Socket.
[  OK  ] Reached target Sockets.
[  OK  ] Reached target Basic System.
 Starting Login Service...
 Starting Permit User Sessions...
 Starting D-Bus System Message Bus...
[  OK  ] Started D-Bus System Message Bus.
[  OK  ] Started Permit User Sessions.
 Starting Console Getty...
[  OK  ] Started Console Getty.
[  OK  ] Reached target Login Prompts.
[  OK  ] Started Login Service.
[  OK  ] Reached target Multi-User System.
[  OK  ] Reached target Graphical Interface.


This is gentoo.

gentoo login: root
Password:
Last login: Mon Dec  9 13:58:42 CST 2013 on console
gentoo ~ # shutdown -h -P now

Broadcast message from root@gentoo (console) (Mon Dec  9 17:10:23 2013):

The system is going down for system halt NOW!
gentoo ~ # [  OK  ] Stopped target Graphical Interface.
[  OK  ] Stopped target Multi-User System.
[  OK  ] Stopped target Login Prompts.
 Stopping Console Getty...
 Stopping Login Service...
 Stopping D-Bus System Message Bus...
[  OK  ] Stopped Login Service.
[  OK  ] Stopped Console Getty.
[  OK  ] Stopped D-Bus System Message Bus.
 Stopping Permit User Sessions...
[  OK  ] Stopped Permit User Sessions.
[  OK  ] Stopped target Basic System.
[  OK  ] Stopped target Paths.
[  OK  ] Stopped target Timers.
[  OK  ] Stopped target Sockets.
[  OK  ] Closed /dev/initctl Compatibility Named Pipe.
[  OK  ] Closed Delayed Shutdown Socket.
[  OK  ] Closed D-Bus System Message Bus Socket.
[  OK  ] Stopped target System Initialization.
[  OK  ] Stopped target Swap.
[  OK  ] Stopped target Local File Systems.
 Unmounting /usr/portage...
 Unmounting /etc/resolv.conf...
 Unmounting /proc/sys/kernel/random/boot_id...
 Unmounting Temporary Directory...
 Stopping Journal Service...
[  OK  ] Stopped target Remote File Systems.
[  OK  ] Unmounted /usr/portage.
[  OK  ] Unmounted /etc/resolv.conf.
[  OK  ] Unmounted /proc/sys/kernel/random/boot_id.
[  OK  ] Unmounted Temporary Directory.
[  OK  ] Reached target Unmount All Filesystems.
[  OK  ] Stopped target Local File Systems (Pre).
 Stopping Remount Root and Kernel File Systems...
[  OK  ] Stopped Remount Root and Kernel File Systems.
[  OK  ] Reached target Shutdown.
Sen

[systemd-devel] [PATCH 1/2] core: support Distribute=n to distribute to n workers

2013-12-09 Thread Shawn Landden
Until there are some use cases for Distribute= w/o
SO_REUSEPORT make it imply that. Otherwise we need
a new config_parse_distribute in load-fragment.c
and gain the same issues of config_parse_syscall,
where NoNewPrivs can be still set to false,
but only if set _after_ SystemCallFilter (only allowed
when root).

Because it takes a while for the service to start up, and
until then we spin in a fast epoll loop, this tends to
start up all the instances all at once. There are a number
of ways we can slow this instanciation down:
 1) Call accept() and pass an additional fd to the service
 2) Use EPOLLET: requires event to be prioritized and always
  dispatched.
 3) Disable and then reenable the event source every time we
 enqueue an instance.

IMHO #1 is not acceptable. For #2, perhaps the new event loop
infrastructure can support a special class for EPOLLET. I
am going to investigate #3 right after sending this patch.
---
 TODO  |  3 +-
 man/systemd.socket.xml| 11 ++
 src/core/dbus-socket.c|  2 +-
 src/core/load-fragment-gperf.gperf.m4 |  1 +
 src/core/socket.c | 64 +++
 src/core/socket.h |  3 ++
 6 files changed, 59 insertions(+), 25 deletions(-)

diff --git a/TODO b/TODO
index 8f9aabc..15233cd 100644
--- a/TODO
+++ b/TODO
@@ -69,7 +69,7 @@ Features:
 
 * rfkill,backlight: we probably should run the load tools inside of the udev 
rules so that the state is properly initialized by the time other software sees 
it
 
-* Add a new Distribute=$NUMBER key to socket units that makes use of 
SO_REUSEPORT to distribute network traffic on $NUMBER instances
+* tmpfiles: when applying ownership to /run/log/journal, also do this for the 
journal fails contained in it
 
 * we probably should replace the left-over uses of strv_append() and replace 
them by strv_push() or strv_extend()
 
@@ -187,7 +187,6 @@ Features:
 * teach ConditionKernelCommandLine= globs or regexes (in order to match 
foobar={no,0,off})
 
 * Support SO_REUSEPORT with socket activation:
-  - Let systemd maintain a pool of servers.
   - Use for seamless upgrades, by running the new server before stopping the
 old.
 
diff --git a/man/systemd.socket.xml b/man/systemd.socket.xml
index 7c10c58..48a4b77 100644
--- a/man/systemd.socket.xml
+++ b/man/systemd.socket.xml
@@ -519,6 +519,17 @@
 
 
 
+Distribute=
+Takes an integer
+value. Systemd will spawn up to
+given number of instances of service each
+listening to the same socket. Default is 0.
+Setting this requires corresponding service to
+be an instansiated service (name ends with 
@.service).
+Useful with Reuseport= 
above.
+
+
+
 SmackLabel=
 SmackLabelIPIn=
 
SmackLabelIPOut=
diff --git a/src/core/dbus-socket.c b/src/core/dbus-socket.c
index 74217df..68c95a0 100644
--- a/src/core/dbus-socket.c
+++ b/src/core/dbus-socket.c
@@ -40,7 +40,6 @@ static int property_get_listen(
 void *userdata,
 sd_bus_error *error) {
 
-
 Socket *s = SOCKET(userdata);
 SocketPort *p;
 int r;
@@ -116,6 +115,7 @@ const sd_bus_vtable bus_socket_vtable[] = {
 SD_BUS_PROPERTY("MessageQueueMessageSize", "x", bus_property_get_long, 
offsetof(Socket, mq_msgsize), 0),
 SD_BUS_PROPERTY("Result", "s", property_get_result, offsetof(Socket, 
result), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
 SD_BUS_PROPERTY("ReusePort", "b",  bus_property_get_bool, 
offsetof(Socket, reuse_port), 0),
+SD_BUS_PROPERTY("Distribute", "u",  bus_property_get_unsigned, 
offsetof(Socket, distribute), 0),
 SD_BUS_PROPERTY("SmackLabel", "s", NULL, offsetof(Socket, smack), 0),
 SD_BUS_PROPERTY("SmackLabelIPIn", "s", NULL, offsetof(Socket, 
smack_ip_in), 0),
 SD_BUS_PROPERTY("SmackLabelIPOut", "s", NULL, offsetof(Socket, 
smack_ip_out), 0),
diff --git a/src/core/load-fragment-gperf.gperf.m4 
b/src/core/load-fragment-gperf.gperf.m4
index a5033b2..de82586 100644
--- a/src/core/load-fragment-gperf.gperf.m4
+++ b/src/core/load-fragment-gperf.gperf.m4
@@ -213,6 +213,7 @@ Socket.PassCredentials,  config_parse_bool, 
 0,
 Socket.PassSecurity, config_parse_bool,  0,
 offsetof(Socket, pass_sec)
 Socket.TCPCongestion,config_parse_string,0,
 offsetof(Socket, tcp_congestion)
 Socket.ReusePort,config_parse_bool,  0,   

[systemd-devel] [PATCH 2/2] epoll and signalfd has been moved into sd event loop

2013-12-09 Thread Shawn Landden
---
 src/core/manager.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/src/core/manager.c b/src/core/manager.c
index f06df54..56c10cf 100644
--- a/src/core/manager.c
+++ b/src/core/manager.c
@@ -22,9 +22,7 @@
 #include 
 #include 
 #include 
-#include 
 #include 
-#include 
 #include 
 #include 
 #include 
-- 
1.8.5.1

___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] [PATCH v3 06/26] dhcp: Add buffer length and invalid cookie tests for DHCP options

2013-12-09 Thread Patrik Flykt
Create an initial simple test program for these two cases.
---
 src/dhcp/test-dhcp-option.c |   51 +++
 1 file changed, 51 insertions(+)
 create mode 100644 src/dhcp/test-dhcp-option.c

diff --git a/src/dhcp/test-dhcp-option.c b/src/dhcp/test-dhcp-option.c
new file mode 100644
index 000..3757e27
--- /dev/null
+++ b/src/dhcp/test-dhcp-option.c
@@ -0,0 +1,51 @@
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+#include "protocol.h"
+#include "internal.h"
+
+static void test_invalid_buffer_length(void)
+{
+DHCPMessage message;
+
+assert(dhcp_option_parse(&message, 0, NULL, NULL) == -EINVAL);
+assert(dhcp_option_parse(&message, sizeof(DHCPMessage), NULL, NULL)
+   == -EINVAL);
+}
+
+static void test_cookie(void)
+{
+DHCPMessage *message;
+size_t len = sizeof(DHCPMessage) + 4;
+uint8_t *opt;
+
+message = malloc0(len);
+
+opt = (uint8_t *)(message + 1);
+opt[0] = 0xff;
+
+assert(dhcp_option_parse(message, len, NULL, NULL) == -EINVAL);
+
+opt[0] = 99;
+opt[1] = 130;
+opt[2] = 83;
+opt[3] = 99;
+
+assert(dhcp_option_parse(message, len, NULL, NULL) == -ENOMSG);
+
+free(message);
+}
+
+int main(int argc, char *argv[])
+{
+test_invalid_buffer_length();
+test_cookie();
+
+return 0;
+}
-- 
1.7.10.4

___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] [PATCH v3 14/26] build: Add libsystemd-dhcp

2013-12-09 Thread Patrik Flykt
---
 Makefile.am |   20 
 1 file changed, 20 insertions(+)

diff --git a/Makefile.am b/Makefile.am
index 5794380..cface06 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -3837,6 +3837,26 @@ lib_LTLIBRARIES += \
 endif
 
 # 
--
+libsystemd_dhcp_la_SOURCES = \
+   src/systemd/sd-dhcp-client.h \
+   src/dhcp/protocol.h \
+   src/dhcp/internal.h \
+   src/dhcp/network.c \
+   src/dhcp/option.c \
+   src/dhcp/client.c
+
+noinst_LTLIBRARIES += \
+   libsystemd-dhcp.la
+
+libsystemd_dhcp_la_CFLAGS = \
+   $(AM_CFLAGS)
+
+libsystemd_dhcp_la_LDFLAGS = \
+   $(AM_LDFLAGS)
+
+libsystemd_dhcp_la_LIBADD = \
+   libsystemd-shared.la
+
 test_dhcp_option_SOURCES = \
src/dhcp/protocol.h \
src/dhcp/internal.h \
-- 
1.7.10.4

___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] [PATCH v3 22/26] dhcp: Add maximum message size option

2013-12-09 Thread Patrik Flykt
Add maximum message size option to keep some DHCP server implementations
from sending too big messages. See ConnMan commit
0c5c862749c05193cf4c513628328c6db02b5222.
---
 src/dhcp/client.c   |   12 
 src/dhcp/protocol.h |1 +
 2 files changed, 13 insertions(+)

diff --git a/src/dhcp/client.c b/src/dhcp/client.c
index c0e4ff0..1a31e3c 100644
--- a/src/dhcp/client.c
+++ b/src/dhcp/client.c
@@ -186,6 +186,7 @@ static int client_packet_init(sd_dhcp_client *client, 
uint8_t type,
   uint8_t **opt, size_t *optlen)
 {
 int err;
+be16_t max_size;
 
 *opt = (uint8_t *)(message + 1);
 
@@ -229,6 +230,17 @@ static int client_packet_init(sd_dhcp_client *client, 
uint8_t type,
  client->req_opts);
 if (err < 0)
 return err;
+
+/* Some DHCP servers will send bigger DHCP packets than the
+   defined default size unless the Maximum Messge Size option
+   is explicitely set */
+max_size = htobe16(DHCP_IP_UDP_SIZE + DHCP_MESSAGE_SIZE +
+   DHCP_CLIENT_MIN_OPTIONS_SIZE);
+err = dhcp_option_append(opt, optlen,
+ DHCP_OPTION_MAXIMUM_MESSAGE_SIZE,
+ 2, &max_size);
+if (err < 0)
+return err;
 }
 
 return 0;
diff --git a/src/dhcp/protocol.h b/src/dhcp/protocol.h
index 95c4f4e..f5f490d 100644
--- a/src/dhcp/protocol.h
+++ b/src/dhcp/protocol.h
@@ -111,6 +111,7 @@ enum {
 DHCP_OPTION_MESSAGE_TYPE= 53,
 DHCP_OPTION_SERVER_IDENTIFIER   = 54,
 DHCP_OPTION_PARAMETER_REQUEST_LIST  = 55,
+DHCP_OPTION_MAXIMUM_MESSAGE_SIZE= 57,
 DHCP_OPTION_CLIENT_IDENTIFIER   = 61,
 DHCP_OPTION_END = 255,
 };
-- 
1.7.10.4

___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] [PATCH v3 12/26] dhcp: Add function for sending a raw packet

2013-12-09 Thread Patrik Flykt
Open a packet socket, create a link level header, send packet and
close socket. Adding it to a separate file makes testing of the
DHCP sending much easier, as the test program can supply any socket
to the DHCP client code.
---
v3: use size_t and set buffer to const

 src/dhcp/internal.h |2 ++
 src/dhcp/network.c  |   55 +++
 2 files changed, 57 insertions(+)
 create mode 100644 src/dhcp/network.c

diff --git a/src/dhcp/internal.h b/src/dhcp/internal.h
index 88e1a08..f3cde61 100644
--- a/src/dhcp/internal.h
+++ b/src/dhcp/internal.h
@@ -25,6 +25,8 @@
 
 #include "protocol.h"
 
+int dhcp_network_send_raw_packet(int index, const void *packet, size_t len);
+
 int dhcp_option_append(uint8_t **buf, size_t *buflen, uint8_t code,
size_t optlen, const void *optval);
 
diff --git a/src/dhcp/network.c b/src/dhcp/network.c
new file mode 100644
index 000..ce21031
--- /dev/null
+++ b/src/dhcp/network.c
@@ -0,0 +1,55 @@
+/***
+  This file is part of systemd.
+
+  Copyright (C) 2013 Intel Corporation. All rights reserved.
+
+  systemd is free software; you can redistribute it and/or modify it
+  under the terms of the GNU Lesser General Public License as published by
+  the Free Software Foundation; either version 2.1 of the License, or
+  (at your option) any later version.
+
+  systemd 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
+  Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public License
+  along with systemd; If not, see .
+***/
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "socket-util.h"
+
+#include "internal.h"
+
+int dhcp_network_send_raw_packet(int index, const void *packet, size_t len)
+{
+_cleanup_close_ int s;
+union sockaddr_union link = {};
+
+s = socket(AF_PACKET, SOCK_DGRAM | SOCK_CLOEXEC, htons(ETH_P_IP));
+if (s < 0)
+return -errno;
+
+link.ll.sll_family = AF_PACKET;
+link.ll.sll_protocol = htons(ETH_P_IP);
+link.ll.sll_ifindex =  index;
+link.ll.sll_halen = ETH_ALEN;
+memset(&link.ll.sll_addr, 0xff, ETH_ALEN);
+
+if (bind(s, &link.sa, sizeof(link.ll)) < 0)
+return -errno;
+
+if (sendto(s, packet, len, 0, &link.sa, sizeof(link.ll)) < 0)
+return -errno;
+
+return 0;
+}
-- 
1.7.10.4

___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] [PATCH v3 20/26] dhcp: Handle received DHCP Offer message

2013-12-09 Thread Patrik Flykt
Create a function for handling the full IP, UDP and DHCP packet
and tie it to the main loop. Verify IP and UDP headers and checksum.
Creat a new lease structure with using the values supplied in the
DHCP message. Free the lease structure when client is stopped.

Split out socket handling into a creation and a sending part. As a
result modify the test code.
---
v3: use stack for 576 byte receive buffer, unref event source before closing
fd, set socket to SOCK_NONBLOCK

 src/dhcp/client.c   |  195 ++-
 src/dhcp/internal.h |7 +-
 src/dhcp/network.c  |   38 +
 src/dhcp/protocol.h |6 ++
 src/dhcp/test-dhcp-client.c |   26 +-
 5 files changed, 251 insertions(+), 21 deletions(-)

diff --git a/src/dhcp/client.c b/src/dhcp/client.c
index 5ab8015..bb0c9b3 100644
--- a/src/dhcp/client.c
+++ b/src/dhcp/client.c
@@ -32,17 +32,31 @@
 
 #define DHCP_CLIENT_MIN_OPTIONS_SIZE312
 
+struct DHCPLease {
+uint32_t lifetime;
+uint32_t address;
+uint32_t server_address;
+uint32_t subnet_mask;
+uint32_t router;
+};
+
+typedef struct DHCPLease DHCPLease;
+
 struct sd_dhcp_client {
 DHCPState state;
 sd_event *event;
 sd_event_source *timeout_resend;
 int index;
+int fd;
+union sockaddr_union link;
+sd_event_source *receive_message;
 uint8_t *req_opts;
 size_t req_opts_size;
 uint32_t last_addr;
 struct ether_addr mac_addr;
 uint32_t xid;
 usec_t start_time;
+DHCPLease *lease;
 };
 
 static const uint8_t default_req_opts[] = {
@@ -128,6 +142,13 @@ static int client_stop(sd_dhcp_client *client, int error)
 assert_return(client->state != DHCP_STATE_INIT &&
   client->state != DHCP_STATE_INIT_REBOOT, -EALREADY);
 
+client->receive_message =
+sd_event_source_unref(client->receive_message);
+
+if (client->fd >= 0)
+close(client->fd);
+client->fd = -1;
+
 client->timeout_resend = sd_event_source_unref(client->timeout_resend);
 
 switch (client->state) {
@@ -135,6 +156,7 @@ static int client_stop(sd_dhcp_client *client, int error)
 case DHCP_STATE_INIT:
 case DHCP_STATE_SELECTING:
 
+client->start_time = 0;
 client->state = DHCP_STATE_INIT;
 break;
 
@@ -148,6 +170,11 @@ static int client_stop(sd_dhcp_client *client, int error)
 break;
 }
 
+if (client->lease) {
+free(client->lease);
+client->lease = NULL;
+}
+
 return 0;
 }
 
@@ -278,9 +305,10 @@ static int client_send_discover(sd_dhcp_client *client, 
uint16_t secs)
 discover->ip.check = client_checksum(&discover->ip,
  sizeof(discover->ip));
 
-err = dhcp_network_send_raw_packet(client->index, discover, len);
+err = dhcp_network_send_raw_socket(client->fd, &client->link,
+   discover, len);
 
-return 0;
+return err;
 }
 
 static int client_timeout_resend(sd_event_source *s, uint64_t usec,
@@ -334,6 +362,154 @@ error:
 return 0;
 }
 
+static int client_parse_offer(uint8_t code, uint8_t len, const uint8_t *option,
+  void *user_data)
+{
+DHCPLease *lease = user_data;
+be32_t val;
+
+switch(code) {
+
+case DHCP_OPTION_IP_ADDRESS_LEASE_TIME:
+if (len == 4) {
+memcpy(&val, option, 4);
+lease->lifetime = be32toh(val);
+}
+
+break;
+
+case DHCP_OPTION_SERVER_IDENTIFIER:
+if (len >= 4)
+memcpy(&lease->server_address, option, 4);
+
+break;
+
+case DHCP_OPTION_SUBNET_MASK:
+if (len >= 4)
+memcpy(&lease->subnet_mask, option, 4);
+
+break;
+
+case DHCP_OPTION_ROUTER:
+if (len >= 4)
+memcpy(&lease->router, option, 4);
+
+break;
+}
+
+return 0;
+}
+
+static int client_receive_offer(sd_dhcp_client *client, DHCPPacket *offer,
+size_t len)
+{
+size_t hdrlen;
+DHCPLease *lease;
+
+if (len < (DHCP_IP_UDP_SIZE + DHCP_MESSAGE_SIZE))
+return -EINVAL;
+
+hdrlen = offer->ip.ihl * 4;
+if (hdrlen < 20 || hdrlen > len || client_checksum(&offer->ip,
+   hdrlen))
+return -EINVAL;
+
+offer->ip.check = offer->udp.len;
+offer->ip.ttl = 0;
+
+if (hdrlen + be16toh(offer->udp.len) > len ||
+client_checksum(&offer->ip.ttl, be16toh(offer->udp.len) + 

[systemd-devel] [PATCH v3 19/26] dhcp: Add timeout and main loop support

2013-12-09 Thread Patrik Flykt
Require a main loop to be set when creating a DHCP client. Set up
a timer to resend DHCP Discover messages and add a 0-2 second
delay to the timeout value. Move to state Selecting after successful
sending of a Discover message.
---
v3: take ref on event loop, unref in free function in patch 26/26
add comment about error value end of client_timeout_resend()

 src/dhcp/client.c|   76 --
 src/dhcp/test-dhcp-client.c  |   17 ++
 src/systemd/sd-dhcp-client.h |4 ++-
 3 files changed, 88 insertions(+), 9 deletions(-)

diff --git a/src/dhcp/client.c b/src/dhcp/client.c
index 60a1b4c..5ab8015 100644
--- a/src/dhcp/client.c
+++ b/src/dhcp/client.c
@@ -34,12 +34,15 @@
 
 struct sd_dhcp_client {
 DHCPState state;
+sd_event *event;
+sd_event_source *timeout_resend;
 int index;
 uint8_t *req_opts;
 size_t req_opts_size;
 uint32_t last_addr;
 struct ether_addr mac_addr;
 uint32_t xid;
+usec_t start_time;
 };
 
 static const uint8_t default_req_opts[] = {
@@ -125,6 +128,8 @@ static int client_stop(sd_dhcp_client *client, int error)
 assert_return(client->state != DHCP_STATE_INIT &&
   client->state != DHCP_STATE_INIT_REBOOT, -EALREADY);
 
+client->timeout_resend = sd_event_source_unref(client->timeout_resend);
+
 switch (client->state) {
 
 case DHCP_STATE_INIT:
@@ -278,8 +283,61 @@ static int client_send_discover(sd_dhcp_client *client, 
uint16_t secs)
 return 0;
 }
 
+static int client_timeout_resend(sd_event_source *s, uint64_t usec,
+ void *userdata)
+{
+sd_dhcp_client *client = userdata;
+usec_t next_timeout;
+uint16_t secs;
+int err = 0;
+
+switch (client->state) {
+case DHCP_STATE_INIT:
+case DHCP_STATE_SELECTING:
+
+if (!client->start_time)
+client->start_time = usec;
+
+secs = (usec - client->start_time) / USEC_PER_SEC;
+
+next_timeout = usec + 2 * USEC_PER_SEC + (random() & 0x1f);
+
+err = sd_event_add_monotonic(client->event, next_timeout,
+ 10 * USEC_PER_MSEC,
+ client_timeout_resend, client,
+ &client->timeout_resend);
+if (err < 0)
+goto error;
+
+if (client_send_discover(client, secs) >= 0)
+client->state = DHCP_STATE_SELECTING;
+
+break;
+
+case DHCP_STATE_INIT_REBOOT:
+case DHCP_STATE_REBOOTING:
+case DHCP_STATE_REQUESTING:
+case DHCP_STATE_BOUND:
+case DHCP_STATE_RENEWING:
+case DHCP_STATE_REBINDING:
+
+break;
+}
+
+return 0;
+
+error:
+client_stop(client, err);
+
+/* Errors were dealt with when stopping the client, don't spill
+   errors into the event loop handler */
+return 0;
+}
+
 int sd_dhcp_client_start(sd_dhcp_client *client)
 {
+int err;
+
 assert_return(client, -EINVAL);
 assert_return(client->index >= 0, -EINVAL);
 assert_return(client->state == DHCP_STATE_INIT ||
@@ -287,7 +345,18 @@ int sd_dhcp_client_start(sd_dhcp_client *client)
 
 client->xid = random_u();
 
-return client_send_discover(client, 0);
+err = sd_event_add_monotonic(client->event, now(CLOCK_MONOTONIC), 0,
+ client_timeout_resend, client,
+ &client->timeout_resend);
+if (err < 0)
+goto error;
+
+return 0;
+
+error:
+client_stop(client, err);
+
+return err;
 }
 
 int sd_dhcp_client_stop(sd_dhcp_client *client)
@@ -295,14 +364,17 @@ int sd_dhcp_client_stop(sd_dhcp_client *client)
 return client_stop(client, 0);
 }
 
-sd_dhcp_client *sd_dhcp_client_new(void)
+sd_dhcp_client *sd_dhcp_client_new(sd_event *event)
 {
 sd_dhcp_client *client;
 
+assert_return(event, NULL);
+
 client = new0(sd_dhcp_client, 1);
 if (!client)
 return NULL;
 
+client->event = sd_event_ref(event);
 client->state = DHCP_STATE_INIT;
 client->index = -1;
 
diff --git a/src/dhcp/test-dhcp-client.c b/src/dhcp/test-dhcp-client.c
index 2e6b732..28762e6 100644
--- a/src/dhcp/test-dhcp-client.c
+++ b/src/dhcp/test-dhcp-client.c
@@ -34,11 +34,11 @@ static struct ether_addr mac_addr = {
 .ether_addr_octet = {'A', 'B', 'C', '1', '2', '3'}
 };
 
-static void test_request_basic(void)
+static void test_request_basic(sd_event *e)
 {
 sd_dhcp_client *client;
 
-client = sd_dhcp_client_new();
+client = sd_dhcp_client_new(e);
 
 assert(client);
 
@@ -172,12 +172,12 @@ int

[systemd-devel] [PATCH v3 26/26] dhcp: Add function to free DHCP client data

2013-12-09 Thread Patrik Flykt
---
 src/dhcp/client.c|   13 +
 src/systemd/sd-dhcp-client.h |1 +
 2 files changed, 14 insertions(+)

diff --git a/src/dhcp/client.c b/src/dhcp/client.c
index d93cceb..2a479e4 100644
--- a/src/dhcp/client.c
+++ b/src/dhcp/client.c
@@ -961,6 +961,19 @@ int sd_dhcp_client_stop(sd_dhcp_client *client)
 return client_stop(client, DHCP_EVENT_STOP);
 }
 
+sd_dhcp_client *sd_dhcp_client_free(sd_dhcp_client *client)
+{
+assert_return(client, NULL);
+
+sd_dhcp_client_stop(client);
+
+sd_event_unref(client->event);
+free(client->req_opts);
+free(client);
+
+return NULL;
+}
+
 sd_dhcp_client *sd_dhcp_client_new(sd_event *event)
 {
 sd_dhcp_client *client;
diff --git a/src/systemd/sd-dhcp-client.h b/src/systemd/sd-dhcp-client.h
index 395c12d..fdc5b2d 100644
--- a/src/systemd/sd-dhcp-client.h
+++ b/src/systemd/sd-dhcp-client.h
@@ -57,6 +57,7 @@ int sd_dhcp_client_get_router(sd_dhcp_client *client, struct 
in_addr *addr);
 
 int sd_dhcp_client_stop(sd_dhcp_client *client);
 int sd_dhcp_client_start(sd_dhcp_client *client);
+sd_dhcp_client *sd_dhcp_client_free(sd_dhcp_client *client);
 sd_dhcp_client *sd_dhcp_client_new(sd_event *event);
 
 #endif
-- 
1.7.10.4

___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] [PATCH v3 03/26] dhcp: Add test for DHCP client initialization and parameter setting

2013-12-09 Thread Patrik Flykt
---
 src/dhcp/test-dhcp-client.c |   81 +++
 1 file changed, 81 insertions(+)
 create mode 100644 src/dhcp/test-dhcp-client.c

diff --git a/src/dhcp/test-dhcp-client.c b/src/dhcp/test-dhcp-client.c
new file mode 100644
index 000..cb2f652
--- /dev/null
+++ b/src/dhcp/test-dhcp-client.c
@@ -0,0 +1,81 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+/***
+  This file is part of systemd.
+
+  Copyright (C) 2013 Intel Corporation. All rights reserved.
+
+  systemd is free software; you can redistribute it and/or modify it
+  under the terms of the GNU Lesser General Public License as published by
+  the Free Software Foundation; either version 2.1 of the License, or
+  (at your option) any later version.
+
+  systemd 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
+  Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public License
+  along with systemd; If not, see .
+***/
+
+#include 
+#include 
+#include 
+
+#include "protocol.h"
+#include "sd-dhcp-client.h"
+
+static void test_request_basic(void)
+{
+sd_dhcp_client *client;
+
+client = sd_dhcp_client_new();
+
+assert(client);
+
+assert(sd_dhcp_client_set_request_option(NULL, 0) == -EINVAL);
+assert(sd_dhcp_client_set_request_address(NULL, NULL) == -EINVAL);
+assert(sd_dhcp_client_set_index(NULL, 0) == -EINVAL);
+
+assert(sd_dhcp_client_set_index(client, 15) == 0);
+assert(sd_dhcp_client_set_index(client, -42) == -EINVAL);
+assert(sd_dhcp_client_set_index(client, -1) == 0);
+
+assert(sd_dhcp_client_set_request_option(client,
+DHCP_OPTION_SUBNET_MASK) == -EEXIST);
+assert(sd_dhcp_client_set_request_option(client,
+DHCP_OPTION_ROUTER) == -EEXIST);
+assert(sd_dhcp_client_set_request_option(client,
+DHCP_OPTION_HOST_NAME) == -EEXIST);
+assert(sd_dhcp_client_set_request_option(client,
+DHCP_OPTION_DOMAIN_NAME) == -EEXIST);
+assert(sd_dhcp_client_set_request_option(client,
+DHCP_OPTION_DOMAIN_NAME_SERVER)
+== -EEXIST);
+assert(sd_dhcp_client_set_request_option(client,
+DHCP_OPTION_NTP_SERVER) == -EEXIST);
+
+assert(sd_dhcp_client_set_request_option(client,
+DHCP_OPTION_PAD) == -EINVAL);
+assert(sd_dhcp_client_set_request_option(client,
+DHCP_OPTION_END) == -EINVAL);
+assert(sd_dhcp_client_set_request_option(client,
+DHCP_OPTION_MESSAGE_TYPE) == -EINVAL);
+assert(sd_dhcp_client_set_request_option(client,
+DHCP_OPTION_OVERLOAD) == -EINVAL);
+assert(sd_dhcp_client_set_request_option(client,
+DHCP_OPTION_PARAMETER_REQUEST_LIST)
+== -EINVAL);
+
+assert(sd_dhcp_client_set_request_option(client, 33) == 0);
+assert(sd_dhcp_client_set_request_option(client, 33) == -EEXIST);
+assert(sd_dhcp_client_set_request_option(client, 44) == 0);
+}
+
+int main(int argc, char *argv[])
+{
+test_request_basic();
+
+return 0;
+}
-- 
1.7.10.4

___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] [PATCH v3 18/26] build: Add dependency on libsystemd-bus needed for main loop

2013-12-09 Thread Patrik Flykt
---
 Makefile.am |6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index 1b9edf2..cfa9b4b 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -3855,7 +3855,8 @@ libsystemd_dhcp_la_LDFLAGS = \
$(AM_LDFLAGS)
 
 libsystemd_dhcp_la_LIBADD = \
-   libsystemd-shared.la
+   libsystemd-shared.la \
+   libsystemd-bus.la
 
 test_dhcp_option_SOURCES = \
src/dhcp/protocol.h \
@@ -3876,7 +3877,8 @@ test_dhcp_client_SOURCES = \
src/dhcp/test-dhcp-client.c
 
 test_dhcp_client_LDADD = \
-   libsystemd-shared.la
+   libsystemd-shared.la \
+   libsystemd-bus.la
 
 tests += \
test-dhcp-option \
-- 
1.7.10.4

___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] [PATCH v3 16/26] dhcp: Support seconds elapsed since start of DHCP negotiation

2013-12-09 Thread Patrik Flykt
It was noticed by Grant Erickson in ConnMan commit
95e15c09350acf58d4707056ae2614570883ef66 that:

   "Certain DHCP servers, such as that implemented in Mac OS X
(< 10.7) for its "Internet Sharing" feature, refuse to issue
a DHCP lease to clients that have not set a non-zero value
in their DISCOVER or REQUEST packets."
---
 src/dhcp/client.c |   14 +-
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/src/dhcp/client.c b/src/dhcp/client.c
index 4d0034f..665f986 100644
--- a/src/dhcp/client.c
+++ b/src/dhcp/client.c
@@ -120,8 +120,8 @@ int sd_dhcp_client_set_mac(sd_dhcp_client *client,
 }
 
 static int client_packet_init(sd_dhcp_client *client, uint8_t type,
-  DHCPMessage *message, uint8_t **opt,
-  size_t *optlen)
+  DHCPMessage *message, uint16_t secs,
+  uint8_t **opt, size_t *optlen)
 {
 int err;
 
@@ -136,6 +136,10 @@ static int client_packet_init(sd_dhcp_client *client, 
uint8_t type,
 message->hlen = ETHER_ADDR_LEN;
 message->xid = htobe32(client->xid);
 
+/* Although 'secs' field is a SHOULD in RFC 2131, certain DHCP servers
+   refuse to issue an DHCP lease if 'secs' is set to zero */
+message->secs = htobe16(secs);
+
 memcpy(&message->chaddr, &client->mac_addr, ETH_ALEN);
 (*opt)[0] = 0x63;
 (*opt)[1] = 0x82;
@@ -189,7 +193,7 @@ static uint16_t client_checksum(void *buf, int len)
 return ~((sum & 0x) + (sum >> 16));
 }
 
-static int client_send_discover(sd_dhcp_client *client)
+static int client_send_discover(sd_dhcp_client *client, uint16_t secs)
 {
 int err = 0;
 _cleanup_free_ DHCPPacket *discover;
@@ -205,7 +209,7 @@ static int client_send_discover(sd_dhcp_client *client)
 return -ENOMEM;
 
 err = client_packet_init(client, DHCP_DISCOVER, &discover->dhcp,
- &opt, &optlen);
+ secs, &opt, &optlen);
 if (err < 0)
 return err;
 
@@ -256,7 +260,7 @@ int sd_dhcp_client_start(sd_dhcp_client *client)
 
 client->xid = random_u();
 
-return client_send_discover(client);
+return client_send_discover(client, 0);
 }
 
 sd_dhcp_client *sd_dhcp_client_new(void)
-- 
1.7.10.4

___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] [PATCH v3 11/26] shared: Add struct sockaddr_ll to sockaddr_union

2013-12-09 Thread Patrik Flykt
---
 src/shared/socket-util.h |2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/shared/socket-util.h b/src/shared/socket-util.h
index d42a2fe..84ebc30 100644
--- a/src/shared/socket-util.h
+++ b/src/shared/socket-util.h
@@ -27,6 +27,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "macro.h"
 #include "util.h"
@@ -38,6 +39,7 @@ union sockaddr_union {
 struct sockaddr_un un;
 struct sockaddr_nl nl;
 struct sockaddr_storage storage;
+struct sockaddr_ll ll;
 };
 
 typedef struct SocketAddress {
-- 
1.7.10.4

___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] [PATCH v3 25/26] dhcp: Add notification callback

2013-12-09 Thread Patrik Flykt
Define a notification callback and events for stopping and client
lease expiry. Add functions to fetch IP parameters from a lease.
---
 src/dhcp/client.c|  112 +-
 src/systemd/sd-dhcp-client.h |   13 +
 2 files changed, 124 insertions(+), 1 deletion(-)

diff --git a/src/dhcp/client.c b/src/dhcp/client.c
index 2e0bdc1..d93cceb 100644
--- a/src/dhcp/client.c
+++ b/src/dhcp/client.c
@@ -63,6 +63,8 @@ struct sd_dhcp_client {
 sd_event_source *timeout_t1;
 sd_event_source *timeout_t2;
 sd_event_source *timeout_expire;
+sd_dhcp_client_cb_t cb;
+void *userdata;
 DHCPLease *lease;
 };
 
@@ -75,6 +77,17 @@ static const uint8_t default_req_opts[] = {
 DHCP_OPTION_NTP_SERVER,
 };
 
+int sd_dhcp_client_set_callback(sd_dhcp_client *client, sd_dhcp_client_cb_t cb,
+void *userdata)
+{
+assert_return(client, -EINVAL);
+
+client->cb = cb;
+client->userdata = userdata;
+
+return 0;
+}
+
 int sd_dhcp_client_set_request_option(sd_dhcp_client *client, uint8_t option)
 {
 size_t i;
@@ -143,8 +156,99 @@ int sd_dhcp_client_set_mac(sd_dhcp_client *client,
 return 0;
 }
 
+int sd_dhcp_client_get_address(sd_dhcp_client *client, struct in_addr *addr)
+{
+assert_return(client, -EINVAL);
+assert_return(addr, -EINVAL);
+
+switch (client->state) {
+case DHCP_STATE_INIT:
+case DHCP_STATE_SELECTING:
+case DHCP_STATE_INIT_REBOOT:
+case DHCP_STATE_REBOOTING:
+case DHCP_STATE_REQUESTING:
+return -EADDRNOTAVAIL;
+
+case DHCP_STATE_BOUND:
+case DHCP_STATE_RENEWING:
+case DHCP_STATE_REBINDING:
+addr->s_addr = client->lease->address;
+
+break;
+}
+
+return 0;
+}
+
+int sd_dhcp_client_get_netmask(sd_dhcp_client *client, struct in_addr *addr)
+{
+assert_return(client, -EINVAL);
+assert_return(addr, -EINVAL);
+
+switch (client->state) {
+case DHCP_STATE_INIT:
+case DHCP_STATE_SELECTING:
+case DHCP_STATE_INIT_REBOOT:
+case DHCP_STATE_REBOOTING:
+case DHCP_STATE_REQUESTING:
+return -EADDRNOTAVAIL;
+
+case DHCP_STATE_BOUND:
+case DHCP_STATE_RENEWING:
+case DHCP_STATE_REBINDING:
+addr->s_addr = client->lease->subnet_mask;
+
+break;
+}
+
+return 0;
+}
+
+int sd_dhcp_client_prefixlen(const struct in_addr *addr)
+{
+int len = 0;
+uint32_t mask;
+
+assert_return(addr, -EADDRNOTAVAIL);
+
+mask = be32toh(addr->s_addr);
+while (mask) {
+len++;
+mask = mask << 1;
+}
+
+return len;
+}
+
+int sd_dhcp_client_get_router(sd_dhcp_client *client, struct in_addr *addr)
+{
+assert_return(client, -EINVAL);
+assert_return(addr, -EINVAL);
+
+switch (client->state) {
+case DHCP_STATE_INIT:
+case DHCP_STATE_SELECTING:
+case DHCP_STATE_INIT_REBOOT:
+case DHCP_STATE_REBOOTING:
+case DHCP_STATE_REQUESTING:
+return -EADDRNOTAVAIL;
+
+case DHCP_STATE_BOUND:
+case DHCP_STATE_RENEWING:
+case DHCP_STATE_REBINDING:
+addr->s_addr = client->lease->router;
+
+break;
+}
+
+return 0;
+}
+
 static int client_notify(sd_dhcp_client *client, int event)
 {
+if (client->cb)
+client->cb(client, event, client->userdata);
+
 return 0;
 }
 
@@ -169,6 +273,8 @@ static int client_stop(sd_dhcp_client *client, int error)
 
 client->attempt = 1;
 
+client_notify(client, error);
+
 switch (client->state) {
 
 case DHCP_STATE_INIT:
@@ -463,6 +569,10 @@ error:
 static int client_timeout_expire(sd_event_source *s, uint64_t usec,
  void *userdata)
 {
+sd_dhcp_client *client = userdata;
+
+client_stop(client, DHCP_EVENT_EXPIRED);
+
 return 0;
 }
 
@@ -848,7 +958,7 @@ error:
 
 int sd_dhcp_client_stop(sd_dhcp_client *client)
 {
-return client_stop(client, 0);
+return client_stop(client, DHCP_EVENT_STOP);
 }
 
 sd_dhcp_client *sd_dhcp_client_new(sd_event *event)
diff --git a/src/systemd/sd-dhcp-client.h b/src/systemd/sd-dhcp-client.h
index ed72cf1..395c12d 100644
--- a/src/systemd/sd-dhcp-client.h
+++ b/src/systemd/sd-dhcp-client.h
@@ -28,13 +28,21 @@
 #include "sd-event.h"
 
 enum {
+DHCP_EVENT_STOP = 0,
 DHCP_EVENT_NO_LEASE = 1,
 DHCP_EVENT_IP_ACQUIRE   = 2,
 DHCP_EVENT_IP_CHANGE= 3,
+DHCP_EVENT_EXPIRED  = 4,
 };
 
 typedef struct sd_dhcp_client sd_dhcp_client;
 
+typedef void (*sd_dhcp_client_cb_t)(sd_dhcp_client *c

[systemd-devel] [PATCH v3 01/26] dhcp: Add DHCP protocol structures and initial defines

2013-12-09 Thread Patrik Flykt
Create a new directory to host DHCP components.
---
 src/dhcp/protocol.h |  104 +++
 1 file changed, 104 insertions(+)
 create mode 100644 src/dhcp/protocol.h

diff --git a/src/dhcp/protocol.h b/src/dhcp/protocol.h
new file mode 100644
index 000..d375467
--- /dev/null
+++ b/src/dhcp/protocol.h
@@ -0,0 +1,104 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+#pragma once
+
+/***
+  This file is part of systemd.
+
+  Copyright (C) 2013 Intel Corporation. All rights reserved.
+
+  systemd is free software; you can redistribute it and/or modify it
+  under the terms of the GNU Lesser General Public License as published by
+  the Free Software Foundation; either version 2.1 of the License, or
+  (at your option) any later version.
+
+  systemd 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
+  Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public License
+  along with systemd; If not, see .
+***/
+
+#include 
+#include 
+#include 
+
+#include "macro.h"
+#include "sparse-endian.h"
+
+struct DHCPMessage {
+uint8_t op;
+uint8_t htype;
+uint8_t hlen;
+uint8_t hops;
+be32_t xid;
+be16_t secs;
+be16_t flags;
+uint32_t ciaddr;
+uint32_t yiaddr;
+uint32_t siaddr;
+uint32_t giaddr;
+uint8_t chaddr[16];
+uint8_t sname[64];
+uint8_t file[128];
+} _packed_;
+
+typedef struct DHCPMessage DHCPMessage;
+
+struct DHCPPacket {
+struct iphdr ip;
+struct udphdr udp;
+DHCPMessage dhcp;
+} _packed_;
+
+typedef struct DHCPPacket DHCPPacket;
+
+enum DHCPState {
+DHCP_STATE_INIT = 0,
+DHCP_STATE_SELECTING= 1,
+DHCP_STATE_INIT_REBOOT  = 2,
+DHCP_STATE_REBOOTING= 3,
+DHCP_STATE_REQUESTING   = 4,
+DHCP_STATE_BOUND= 5,
+DHCP_STATE_RENEWING = 6,
+DHCP_STATE_REBINDING= 7,
+};
+
+typedef enum DHCPState DHCPState;
+
+enum {
+BOOTREQUEST = 1,
+BOOTREPLY   = 2,
+};
+
+enum {
+DHCP_DISCOVER   = 1,
+DHCP_OFFER  = 2,
+DHCP_REQUEST= 3,
+DHCP_DECLINE= 4,
+DHCP_ACK= 5,
+DHCP_NAK= 6,
+DHCP_RELEASE= 7,
+};
+
+enum {
+DHCP_OVERLOAD_FILE  = 1,
+DHCP_OVERLOAD_SNAME = 2,
+};
+
+enum {
+DHCP_OPTION_PAD = 0,
+DHCP_OPTION_SUBNET_MASK = 1,
+DHCP_OPTION_ROUTER  = 3,
+DHCP_OPTION_DOMAIN_NAME_SERVER  = 6,
+DHCP_OPTION_HOST_NAME   = 12,
+DHCP_OPTION_DOMAIN_NAME = 15,
+DHCP_OPTION_NTP_SERVER  = 42,
+DHCP_OPTION_REQUESTED_IP_ADDRESS= 50,
+DHCP_OPTION_OVERLOAD= 52,
+DHCP_OPTION_MESSAGE_TYPE= 53,
+DHCP_OPTION_PARAMETER_REQUEST_LIST  = 55,
+DHCP_OPTION_END = 255,
+};
-- 
1.7.10.4

___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] [PATCH v3 02/26] dhcp: Add DHCP client initialization

2013-12-09 Thread Patrik Flykt
Provide functionality for initializing a DHCP client struct, setting
interface index, last used address and additional options to request.
On initialization the most useful options are added by default.
---
v3: fix OOM check, #ifdef in public header, fix struct prefix

 src/dhcp/client.c|  125 ++
 src/systemd/sd-dhcp-client.h |   36 
 2 files changed, 161 insertions(+)
 create mode 100644 src/dhcp/client.c
 create mode 100644 src/systemd/sd-dhcp-client.h

diff --git a/src/dhcp/client.c b/src/dhcp/client.c
new file mode 100644
index 000..dc4e409
--- /dev/null
+++ b/src/dhcp/client.c
@@ -0,0 +1,125 @@
+/***
+  This file is part of systemd.
+
+  Copyright (C) 2013 Intel Corporation. All rights reserved.
+
+  systemd is free software; you can redistribute it and/or modify it
+  under the terms of the GNU Lesser General Public License as published by
+  the Free Software Foundation; either version 2.1 of the License, or
+  (at your option) any later version.
+
+  systemd 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
+  Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public License
+  along with systemd; If not, see .
+***/
+
+#include 
+#include 
+#include 
+#include 
+
+#include "util.h"
+#include "list.h"
+
+#include "protocol.h"
+#include "sd-dhcp-client.h"
+
+struct sd_dhcp_client {
+DHCPState state;
+int index;
+uint8_t *req_opts;
+size_t req_opts_size;
+uint32_t last_addr;
+};
+
+static const uint8_t default_req_opts[] = {
+DHCP_OPTION_SUBNET_MASK,
+DHCP_OPTION_ROUTER,
+DHCP_OPTION_HOST_NAME,
+DHCP_OPTION_DOMAIN_NAME,
+DHCP_OPTION_DOMAIN_NAME_SERVER,
+DHCP_OPTION_NTP_SERVER,
+};
+
+int sd_dhcp_client_set_request_option(sd_dhcp_client *client, uint8_t option)
+{
+size_t i;
+
+assert_return(client, -EINVAL);
+assert_return (client->state == DHCP_STATE_INIT, -EBUSY);
+
+switch(option) {
+case DHCP_OPTION_PAD:
+case DHCP_OPTION_OVERLOAD:
+case DHCP_OPTION_MESSAGE_TYPE:
+case DHCP_OPTION_PARAMETER_REQUEST_LIST:
+case DHCP_OPTION_END:
+return -EINVAL;
+
+default:
+break;
+}
+
+for (i = 0; i < client->req_opts_size; i++)
+if (client->req_opts[i] == option)
+return -EEXIST;
+
+if (!GREEDY_REALLOC(client->req_opts, client->req_opts_size,
+client->req_opts_size + 1))
+return -ENOMEM;
+
+client->req_opts[client->req_opts_size - 1] = option;
+
+return 0;
+}
+
+int sd_dhcp_client_set_request_address(sd_dhcp_client *client,
+   const struct in_addr *last_addr)
+{
+assert_return(client, -EINVAL);
+assert_return(client->state == DHCP_STATE_INIT, -EBUSY);
+
+if (last_addr)
+client->last_addr = last_addr->s_addr;
+else
+client->last_addr = INADDR_ANY;
+
+return 0;
+}
+
+int sd_dhcp_client_set_index(sd_dhcp_client *client, int interface_index)
+{
+assert_return(client, -EINVAL);
+assert_return(client->state == DHCP_STATE_INIT, -EBUSY);
+assert_return(interface_index >= -1, -EINVAL);
+
+client->index = interface_index;
+
+return 0;
+}
+
+sd_dhcp_client *sd_dhcp_client_new(void)
+{
+sd_dhcp_client *client;
+
+client = new0(sd_dhcp_client, 1);
+if (!client)
+return NULL;
+
+client->state = DHCP_STATE_INIT;
+client->index = -1;
+
+client->req_opts_size = ELEMENTSOF(default_req_opts);
+
+client->req_opts = memdup(default_req_opts, client->req_opts_size);
+if (!client->req_opts) {
+free(client);
+return NULL;
+}
+
+return client;
+}
diff --git a/src/systemd/sd-dhcp-client.h b/src/systemd/sd-dhcp-client.h
new file mode 100644
index 000..9b19a1d
--- /dev/null
+++ b/src/systemd/sd-dhcp-client.h
@@ -0,0 +1,36 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+#ifndef foosddhcpclienthfoo
+#define foosddhcpclienthfoo
+
+/***
+  This file is part of systemd.
+
+  Copyright (C) 2013 Intel Corporation. All rights reserved.
+
+  systemd is free software; you can redistribute it and/or modify it
+  under the terms of the GNU Lesser General Public License as published by
+  the Free Software Foundation; either version 2.1 of the License, or
+  (at your option) any later version.
+
+  systemd is distributed in the hope that it will be useful, but
+  WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS F

[systemd-devel] [PATCH v3 09/26] dhcp: Add option append tests

2013-12-09 Thread Patrik Flykt
Add checks for invalid lengths and parameters when using the option
appending function. Add also checks for adding options, see to it
that the resulting array is identical to the array of options added.
---
 src/dhcp/test-dhcp-option.c |   72 +++
 1 file changed, 72 insertions(+)

diff --git a/src/dhcp/test-dhcp-option.c b/src/dhcp/test-dhcp-option.c
index f9f1cf6..b85da79 100644
--- a/src/dhcp/test-dhcp-option.c
+++ b/src/dhcp/test-dhcp-option.c
@@ -289,6 +289,76 @@ static void test_options(struct option_desc *desc)
 printf("DHCP type %s\n", dhcp_type(res));
 }
 
+static uint8_t result[64] = {
+'A', 'B', 'C', 'D',
+};
+
+static uint8_t options[64] = {
+'A', 'B', 'C', 'D',
+160, 2, 0x11, 0x12,
+0,
+31, 8, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38,
+0,
+55, 3, 0x51, 0x52, 0x53,
+17, 7, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
+255
+};
+
+static void test_option_set(void)
+{
+size_t len, oldlen;
+int pos, i;
+uint8_t *opt;
+
+assert(dhcp_option_append(NULL, NULL, 0, 0, NULL) == -EINVAL);
+
+len = 0;
+opt = &result[0];
+assert(dhcp_option_append(&opt, NULL, 0, 0, NULL) == -EINVAL);
+assert(opt == &result[0] && len == 0);
+
+assert(dhcp_option_append(&opt, &len, DHCP_OPTION_PAD,
+  0, NULL) == -ENOBUFS);
+assert(opt == &result[0] && len == 0);
+
+opt = &result[4];
+len = 1;
+assert(dhcp_option_append(&opt, &len, DHCP_OPTION_PAD,
+0, NULL) >= 0);
+assert(opt == &result[5] && len == 0);
+
+pos = 4;
+len = 60;
+while (pos < 64 && options[pos] != DHCP_OPTION_END) {
+opt = &result[pos];
+oldlen = len;
+
+assert(dhcp_option_append(&opt, &len, options[pos],
+  options[pos + 1],
+  &options[pos + 2]) >= 0);
+
+if (options[pos] == DHCP_OPTION_PAD) {
+assert(opt == &result[pos + 1]);
+assert(len == oldlen - 1);
+pos++;
+} else {
+assert(opt == &result[pos + 2 + options[pos + 1]]);
+assert(len == oldlen - 2 - options[pos + 1]);
+pos += 2 + options[pos + 1];
+}
+}
+
+for (i = 0; i < pos; i++) {
+if (verbose)
+printf("%2d: 0x%02x(0x%02x)\n", i, result[i],
+   options[i]);
+assert(result[i] == options[i]);
+}
+
+if (verbose)
+printf ("\n");
+}
+
 int main(int argc, char *argv[])
 {
 unsigned int i;
@@ -301,5 +371,7 @@ int main(int argc, char *argv[])
 for (i = 0; i < ELEMENTSOF(option_tests); i++)
 test_options(&option_tests[i]);
 
+test_option_set();
+
 return 0;
 }
-- 
1.7.10.4

___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] [PATCH v3 07/26] build: Add DHCP option test

2013-12-09 Thread Patrik Flykt
---
 Makefile.am |   10 ++
 1 file changed, 10 insertions(+)

diff --git a/Makefile.am b/Makefile.am
index 4e13370..5794380 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -3837,6 +3837,15 @@ lib_LTLIBRARIES += \
 endif
 
 # 
--
+test_dhcp_option_SOURCES = \
+   src/dhcp/protocol.h \
+   src/dhcp/internal.h \
+   src/dhcp/option.c \
+   src/dhcp/test-dhcp-option.c
+
+test_dhcp_option_LDADD = \
+   libsystemd-shared.la
+
 test_dhcp_client_SOURCES = \
src/dhcp/protocol.h \
src/systemd/sd-dhcp-client.h \
@@ -3847,6 +3856,7 @@ test_dhcp_client_LDADD = \
libsystemd-shared.la
 
 tests += \
+   test-dhcp-option \
test-dhcp-client
 
 # 
--
-- 
1.7.10.4

___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] [PATCH v3 13/26] dhcp: Add DHCP discover sending

2013-12-09 Thread Patrik Flykt
On starting the client, use the supplied interface mac address and create
a transaction id. Puzzle together an IP/UDP/DHCP Discover message, compute
checksums and send it out as a raw packet.

Create an additional function that constructs default options common to
all DHCP messages.

Set the DHCP Client ID option as noticed by Grant Erickson in ConnMan
commit b18d9798b3a0ae46ed87d6d2be8d5a474bf3ab1e:

   "Some Internet gateways and Wi-Fi access points are unhappy when the
DHCPv4 client-id option (61) is missing and will refuse to issue a
DHCP lease."
---
 src/dhcp/client.c|  157 ++
 src/dhcp/protocol.h  |6 ++
 src/systemd/sd-dhcp-client.h |4 ++
 3 files changed, 167 insertions(+)

diff --git a/src/dhcp/client.c b/src/dhcp/client.c
index dc4e409..4d0034f 100644
--- a/src/dhcp/client.c
+++ b/src/dhcp/client.c
@@ -21,19 +21,25 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "util.h"
 #include "list.h"
 
 #include "protocol.h"
+#include "internal.h"
 #include "sd-dhcp-client.h"
 
+#define DHCP_CLIENT_MIN_OPTIONS_SIZE312
+
 struct sd_dhcp_client {
 DHCPState state;
 int index;
 uint8_t *req_opts;
 size_t req_opts_size;
 uint32_t last_addr;
+struct ether_addr mac_addr;
+uint32_t xid;
 };
 
 static const uint8_t default_req_opts[] = {
@@ -102,6 +108,157 @@ int sd_dhcp_client_set_index(sd_dhcp_client *client, int 
interface_index)
 return 0;
 }
 
+int sd_dhcp_client_set_mac(sd_dhcp_client *client,
+   const struct ether_addr *addr)
+{
+assert_return(client, -EINVAL);
+assert_return(client->state == DHCP_STATE_INIT, -EBUSY);
+
+memcpy(&client->mac_addr, addr, ETH_ALEN);
+
+return 0;
+}
+
+static int client_packet_init(sd_dhcp_client *client, uint8_t type,
+  DHCPMessage *message, uint8_t **opt,
+  size_t *optlen)
+{
+int err;
+
+*opt = (uint8_t *)(message + 1);
+
+if (*optlen < 4)
+return -ENOBUFS;
+*optlen -= 4;
+
+message->op = BOOTREQUEST;
+message->htype = 1;
+message->hlen = ETHER_ADDR_LEN;
+message->xid = htobe32(client->xid);
+
+memcpy(&message->chaddr, &client->mac_addr, ETH_ALEN);
+(*opt)[0] = 0x63;
+(*opt)[1] = 0x82;
+(*opt)[2] = 0x53;
+(*opt)[3] = 0x63;
+
+*opt += 4;
+
+err = dhcp_option_append(opt, optlen, DHCP_OPTION_MESSAGE_TYPE, 1,
+ &type);
+if (err < 0)
+return err;
+
+/* Some DHCP servers will refuse to issue an DHCP lease if the Cliient
+   Identifier option is not set */
+err = dhcp_option_append(opt, optlen, DHCP_OPTION_CLIENT_IDENTIFIER,
+ ETH_ALEN, &client->mac_addr);
+if (err < 0)
+return err;
+
+if (type == DHCP_DISCOVER || type == DHCP_REQUEST) {
+err = dhcp_option_append(opt, optlen,
+ DHCP_OPTION_PARAMETER_REQUEST_LIST,
+ client->req_opts_size,
+ client->req_opts);
+if (err < 0)
+return err;
+}
+
+return 0;
+}
+
+static uint16_t client_checksum(void *buf, int len)
+{
+uint32_t sum;
+uint16_t *check;
+int i;
+uint8_t *odd;
+
+sum = 0;
+check = buf;
+
+for (i = 0; i < len / 2 ; i++)
+sum += check[i];
+
+if (len & 0x01) {
+odd = buf;
+sum += odd[len];
+}
+
+return ~((sum & 0x) + (sum >> 16));
+}
+
+static int client_send_discover(sd_dhcp_client *client)
+{
+int err = 0;
+_cleanup_free_ DHCPPacket *discover;
+size_t optlen, len;
+uint8_t *opt;
+
+optlen = DHCP_CLIENT_MIN_OPTIONS_SIZE;
+len = sizeof(DHCPPacket) + optlen;
+
+discover = malloc0(len);
+
+if (!discover)
+return -ENOMEM;
+
+err = client_packet_init(client, DHCP_DISCOVER, &discover->dhcp,
+ &opt, &optlen);
+if (err < 0)
+return err;
+
+if (client->last_addr != INADDR_ANY) {
+err = dhcp_option_append(&opt, &optlen,
+ DHCP_OPTION_REQUESTED_IP_ADDRESS,
+ 4, &client->last_addr);
+if (err < 0)
+return err;
+}
+
+err = dhcp_option_append(&opt, &optlen, DHCP_OPTION_END, 0, NULL);
+if (err < 0)
+return err;
+
+discover->ip.version = IPVERSION;
+discover->ip.ihl = sizeof(discover->ip) >> 2;
+discover->ip.tot_len = htobe16(len);
+
+  

[systemd-devel] [PATCH v3 24/26] dhcp: Compute expire, T1 and T2 timers

2013-12-09 Thread Patrik Flykt
Compute the default T1 and T2 timer values if they were not set by
the DHCP server. Verify that the values are reasonable.
---
 src/dhcp/client.c   |  116 ++-
 src/dhcp/protocol.h |2 +
 2 files changed, 117 insertions(+), 1 deletion(-)

diff --git a/src/dhcp/client.c b/src/dhcp/client.c
index eecbb02..2e0bdc1 100644
--- a/src/dhcp/client.c
+++ b/src/dhcp/client.c
@@ -33,6 +33,8 @@
 #define DHCP_CLIENT_MIN_OPTIONS_SIZE312
 
 struct DHCPLease {
+uint32_t t1;
+uint32_t t2;
 uint32_t lifetime;
 uint32_t address;
 uint32_t server_address;
@@ -57,6 +59,10 @@ struct sd_dhcp_client {
 uint32_t xid;
 usec_t start_time;
 unsigned int attempt;
+usec_t request_sent;
+sd_event_source *timeout_t1;
+sd_event_source *timeout_t2;
+sd_event_source *timeout_expire;
 DHCPLease *lease;
 };
 
@@ -157,6 +163,10 @@ static int client_stop(sd_dhcp_client *client, int error)
 
 client->timeout_resend = sd_event_source_unref(client->timeout_resend);
 
+client->timeout_t1 = sd_event_source_unref(client->timeout_t1);
+client->timeout_t2 = sd_event_source_unref(client->timeout_t2);
+client->timeout_expire = sd_event_source_unref(client->timeout_expire);
+
 client->attempt = 1;
 
 switch (client->state) {
@@ -164,6 +174,7 @@ static int client_stop(sd_dhcp_client *client, int error)
 case DHCP_STATE_INIT:
 case DHCP_STATE_SELECTING:
 case DHCP_STATE_REQUESTING:
+case DHCP_STATE_BOUND:
 
 client->start_time = 0;
 client->state = DHCP_STATE_INIT;
@@ -171,7 +182,6 @@ static int client_stop(sd_dhcp_client *client, int error)
 
 case DHCP_STATE_INIT_REBOOT:
 case DHCP_STATE_REBOOTING:
-case DHCP_STATE_BOUND:
 case DHCP_STATE_RENEWING:
 case DHCP_STATE_REBINDING:
 
@@ -427,6 +437,8 @@ static int client_timeout_resend(sd_event_source *s, 
uint64_t usec,
 if (err < 0 && client->attempt >= 64)
  goto error;
 
+client->request_sent = usec;
+
 break;
 
 case DHCP_STATE_INIT_REBOOT:
@@ -448,6 +460,22 @@ error:
 return 0;
 }
 
+static int client_timeout_expire(sd_event_source *s, uint64_t usec,
+ void *userdata)
+{
+return 0;
+}
+
+static int client_timeout_t2(sd_event_source *s, uint64_t usec, void *userdata)
+{
+return 0;
+}
+
+static int client_timeout_t1(sd_event_source *s, uint64_t usec, void *userdata)
+{
+return 0;
+}
+
 static int client_parse_offer(uint8_t code, uint8_t len, const uint8_t *option,
   void *user_data)
 {
@@ -481,6 +509,22 @@ static int client_parse_offer(uint8_t code, uint8_t len, 
const uint8_t *option,
 memcpy(&lease->router, option, 4);
 
 break;
+
+case DHCP_OPTION_RENEWAL_T1_TIME:
+if (len == 4) {
+memcpy(&val, option, 4);
+lease->t1 = be32toh(val);
+}
+
+break;
+
+case DHCP_OPTION_REBINDING_T2_TIME:
+if (len == 4) {
+memcpy(&val, option, 4);
+lease->t2 = be32toh(val);
+}
+
+break;
 }
 
 return 0;
@@ -610,6 +654,72 @@ error:
 return r;
 }
 
+static uint64_t client_compute_timeout(uint64_t request_sent,
+   uint32_t lifetime)
+{
+return request_sent + (lifetime - 3) * USEC_PER_SEC +
++ (random_u() & 0x1f);
+}
+
+static int client_set_lease_timeouts(sd_dhcp_client *client, uint64_t usec)
+{
+int err;
+uint64_t next_timeout;
+
+if (client->lease->lifetime < 10)
+return -EINVAL;
+
+if (!client->lease->t1)
+client->lease->t1 = client->lease->lifetime / 2;
+
+next_timeout = client_compute_timeout(client->request_sent,
+  client->lease->t1);
+if (next_timeout < usec)
+return -EINVAL;
+
+err = sd_event_add_monotonic(client->event, next_timeout,
+ 10 * USEC_PER_MSEC,
+ client_timeout_t1, client,
+ &client->timeout_t1);
+if (err < 0)
+return err;
+
+if (!client->lease->t2)
+client->lease->t2 = client->lease->lifetime * 7 / 8;
+
+if (client->lease->t2 < client->lease->t1)
+return -EINVAL;
+
+if (client->lease->lifetime < client->lease->t2)
+return -EINVAL;
+
+next_timeout = client_compute_timeout(client->request_sent,
+  cli

[systemd-devel] [PATCH v3 08/26] dhcp: Add tests for DHCP options, file and sname fields

2013-12-09 Thread Patrik Flykt
Add a structure describing the DHCP file, sname and trailing options
fields. Create a messge holding these fields and call the internal
option parsing function.

In the test callback function verify that only regular options are
passed and figure out which part of the DHCP message is the one that
is being processed. As the test program knows the full contents of
the test options in the test structure, skip all non-regular fields
and verify that the option provided to the callback indeed is the
one expected. Check also if non-regular option fields are to be
ignored in the end of the option field as the callback is not called
again and the final check when the whole message has been processed
needs to be successful.

Add a boolean flag for pretty-printing, anticipate there will be a
nice option to toggle it in the future.
---
 src/dhcp/test-dhcp-option.c |  260 ++-
 1 file changed, 257 insertions(+), 3 deletions(-)

diff --git a/src/dhcp/test-dhcp-option.c b/src/dhcp/test-dhcp-option.c
index 3757e27..f9f1cf6 100644
--- a/src/dhcp/test-dhcp-option.c
+++ b/src/dhcp/test-dhcp-option.c
@@ -5,11 +5,74 @@
 #include 
 #include 
 
-#include 
+#include "util.h"
+#include "macro.h"
 
 #include "protocol.h"
 #include "internal.h"
 
+struct option_desc {
+uint8_t sname[64];
+int snamelen;
+uint8_t file[128];
+int filelen;
+uint8_t options[128];
+int len;
+bool success;
+int filepos;
+int snamepos;
+int pos;
+};
+
+static bool verbose = false;
+
+static struct option_desc option_tests[] = {
+{ {}, 0, {}, 0, { 42, 5, 65, 66, 67, 68, 69 }, 7, false, },
+{ {}, 0, {}, 0, { 42, 5, 65, 66, 67, 68, 69, 0, 0,
+  DHCP_OPTION_MESSAGE_TYPE, 1, DHCP_ACK }, 12, true, },
+{ {}, 0, {}, 0, { 8, 255, 70, 71, 72 }, 5, false, },
+{ {}, 0, {}, 0, { 0x35, 0x01, 0x05, 0x36, 0x04, 0x01, 0x00, 0xa8,
+  0xc0, 0x33, 0x04, 0x00, 0x01, 0x51, 0x80, 0x01,
+  0x04, 0xff, 0xff, 0xff, 0x00, 0x03, 0x04, 0xc0,
+  0xa8, 0x00, 0x01, 0x06, 0x04, 0xc0, 0xa8, 0x00,
+  0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, },
+  40, true, },
+{ {}, 0, {}, 0, { DHCP_OPTION_MESSAGE_TYPE, 1, DHCP_OFFER,
+  42, 3, 0, 0, 0 }, 8, true, },
+{ {}, 0, {}, 0, { 42, 2, 1, 2, 44 }, 5, false, },
+
+{ {}, 0,
+  { 222, 3, 1, 2, 3, DHCP_OPTION_MESSAGE_TYPE, 1, DHCP_NAK }, 8,
+  { DHCP_OPTION_OVERLOAD, 1, DHCP_OVERLOAD_FILE }, 3, true, },
+
+{ { 1, 4, 1, 2, 3, 4, DHCP_OPTION_MESSAGE_TYPE, 1, DHCP_ACK }, 9,
+  { 222, 3, 1, 2, 3 }, 5,
+  { DHCP_OPTION_OVERLOAD, 1,
+DHCP_OVERLOAD_FILE|DHCP_OVERLOAD_SNAME }, 3, true, },
+};
+
+static const char *dhcp_type(int type)
+{
+switch(type) {
+case DHCP_DISCOVER:
+return "DHCPDISCOVER";
+case DHCP_OFFER:
+return "DHCPOFFER";
+case DHCP_REQUEST:
+return "DHCPREQUEST";
+case DHCP_DECLINE:
+return "DHCPDECLINE";
+case DHCP_ACK:
+return "DHCPACK";
+case DHCP_NAK:
+return "DHCPNAK";
+case DHCP_RELEASE:
+return "DHCPRELEASE";
+default:
+return "unknown";
+}
+}
+
 static void test_invalid_buffer_length(void)
 {
 DHCPMessage message;
@@ -21,7 +84,7 @@ static void test_invalid_buffer_length(void)
 
 static void test_cookie(void)
 {
-DHCPMessage *message;
+_cleanup_free_ DHCPMessage *message;
 size_t len = sizeof(DHCPMessage) + 4;
 uint8_t *opt;
 
@@ -38,14 +101,205 @@ static void test_cookie(void)
 opt[3] = 99;
 
 assert(dhcp_option_parse(message, len, NULL, NULL) == -ENOMSG);
+}
+
+static DHCPMessage *create_message(uint8_t *options, uint16_t optlen,
+uint8_t *file, uint8_t filelen,
+uint8_t *sname, uint8_t snamelen)
+{
+DHCPMessage *message;
+size_t len = sizeof(DHCPMessage) + 4 + optlen;
+uint8_t *opt;
 
-free(message);
+message = malloc0(len);
+opt = (uint8_t *)(message + 1);
+
+opt[0] = 99;
+opt[1] = 130;
+opt[2] = 83;
+opt[3] = 99;
+
+if (options && optlen)
+memcpy(&opt[4], options, optlen);
+
+if (file && filelen <= 128)
+memcpy(&message->file, file, filelen);
+
+if (sname && snamelen <= 64)
+memcpy(&message->sname, sname, snamelen);
+
+return message;
+}
+
+static void test_ignore_opts(uint8_t *descoption, int *descpos, int *desclen)
+{
+while (*descpos < *desclen) {
+switch(descoption[*descpos]) {
+case DHCP_OPTION_PAD:
+*descpos += 1;
+brea

[systemd-devel] [PATCH v3 23/26] dhcp: Process DHCP Ack/Nak message

2013-12-09 Thread Patrik Flykt
Process a DHCP Ack/Nak in much the same way as an DHCP Offer. Factor
out header verification and process options sent. Add notification
functionality with discrete values for the outcome of the DHCP Ack/
Nak processing.
---
v3: use size_t for length, -ENOMEM for OOM

 src/dhcp/client.c|  142 ++
 src/systemd/sd-dhcp-client.h |6 ++
 2 files changed, 122 insertions(+), 26 deletions(-)

diff --git a/src/dhcp/client.c b/src/dhcp/client.c
index 1a31e3c..eecbb02 100644
--- a/src/dhcp/client.c
+++ b/src/dhcp/client.c
@@ -137,6 +137,11 @@ int sd_dhcp_client_set_mac(sd_dhcp_client *client,
 return 0;
 }
 
+static int client_notify(sd_dhcp_client *client, int event)
+{
+return 0;
+}
+
 static int client_stop(sd_dhcp_client *client, int error)
 {
 assert_return(client, -EINVAL);
@@ -158,6 +163,7 @@ static int client_stop(sd_dhcp_client *client, int error)
 
 case DHCP_STATE_INIT:
 case DHCP_STATE_SELECTING:
+case DHCP_STATE_REQUESTING:
 
 client->start_time = 0;
 client->state = DHCP_STATE_INIT;
@@ -165,7 +171,6 @@ static int client_stop(sd_dhcp_client *client, int error)
 
 case DHCP_STATE_INIT_REBOOT:
 case DHCP_STATE_REBOOTING:
-case DHCP_STATE_REQUESTING:
 case DHCP_STATE_BOUND:
 case DHCP_STATE_RENEWING:
 case DHCP_STATE_REBINDING:
@@ -481,41 +486,53 @@ static int client_parse_offer(uint8_t code, uint8_t len, 
const uint8_t *option,
 return 0;
 }
 
-static int client_receive_offer(sd_dhcp_client *client, DHCPPacket *offer,
-size_t len)
+static int client_verify_headers(sd_dhcp_client *client, DHCPPacket *message,
+ size_t len)
 {
 size_t hdrlen;
-DHCPLease *lease;
 
 if (len < (DHCP_IP_UDP_SIZE + DHCP_MESSAGE_SIZE))
 return -EINVAL;
 
-hdrlen = offer->ip.ihl * 4;
-if (hdrlen < 20 || hdrlen > len || client_checksum(&offer->ip,
+hdrlen = message->ip.ihl * 4;
+if (hdrlen < 20 || hdrlen > len || client_checksum(&message->ip,
hdrlen))
 return -EINVAL;
 
-offer->ip.check = offer->udp.len;
-offer->ip.ttl = 0;
+message->ip.check = message->udp.len;
+message->ip.ttl = 0;
 
-if (hdrlen + be16toh(offer->udp.len) > len ||
-client_checksum(&offer->ip.ttl, be16toh(offer->udp.len) + 12))
+if (hdrlen + be16toh(message->udp.len) > len ||
+client_checksum(&message->ip.ttl, be16toh(message->udp.len) + 12))
 return -EINVAL;
 
-if (be16toh(offer->udp.source) != DHCP_PORT_SERVER ||
-be16toh(offer->udp.dest) != DHCP_PORT_CLIENT)
+if (be16toh(message->udp.source) != DHCP_PORT_SERVER ||
+be16toh(message->udp.dest) != DHCP_PORT_CLIENT)
 return -EINVAL;
 
-if (offer->dhcp.op != BOOTREPLY)
+if (message->dhcp.op != BOOTREPLY)
 return -EINVAL;
 
-if (be32toh(offer->dhcp.xid) != client->xid)
+if (be32toh(message->dhcp.xid) != client->xid)
 return -EINVAL;
 
-if (memcmp(&offer->dhcp.chaddr[0], &client->mac_addr.ether_addr_octet,
+if (memcmp(&message->dhcp.chaddr[0], 
&client->mac_addr.ether_addr_octet,
 ETHER_ADDR_LEN))
 return -EINVAL;
 
+return 0;
+}
+
+static int client_receive_offer(sd_dhcp_client *client, DHCPPacket *offer,
+size_t len)
+{
+int err;
+DHCPLease *lease;
+
+err = client_verify_headers(client, offer, len);
+if (err < 0)
+return err;
+
 lease = new0(DHCPLease, 1);
 if (!lease)
 return -ENOMEM;
@@ -543,13 +560,63 @@ error:
 return -ENOMSG;
 }
 
+static int client_receive_ack(sd_dhcp_client *client, DHCPPacket *offer,
+  size_t len)
+{
+int r;
+DHCPLease *lease;
+
+r = client_verify_headers(client, offer, len);
+if (r < 0)
+return r;
+
+lease = new0(DHCPLease, 1);
+if (!lease)
+return -ENOBUFS;
+
+len = len - DHCP_IP_UDP_SIZE;
+r = dhcp_option_parse(&offer->dhcp, len, client_parse_offer, lease);
+
+if (r != DHCP_ACK)
+goto error;
+
+lease->address = offer->dhcp.yiaddr;
+
+if (lease->address == INADDR_ANY ||
+lease->server_address == INADDR_ANY ||
+lease->subnet_mask == INADDR_ANY || lease->lifetime == 0) {
+r = -ENOMSG;
+goto error;
+}
+
+r = DHCP_EVENT_IP_ACQUIRE;
+if (client->lease) {
+if (client->lease->address != lease->address ||
+client->lease->subnet_mask != lease->subnet

[systemd-devel] [PATCH v3 21/26] dhcp: Send DHCP Request to acquire an IP address

2013-12-09 Thread Patrik Flykt
Create and send a DHCP Request message reusing already existing parts
of the code. This causes factoring out IP and UDP header creation and
moving next timeout calculation to be done every time in the timer
callback function independent of DHCP state. Also add an exponential
part to the timer calculation, bail out if there are errors while
resending the DHCP message for the sixth or more times.
---
 src/dhcp/client.c |  160 -
 1 file changed, 121 insertions(+), 39 deletions(-)

diff --git a/src/dhcp/client.c b/src/dhcp/client.c
index bb0c9b3..c0e4ff0 100644
--- a/src/dhcp/client.c
+++ b/src/dhcp/client.c
@@ -56,6 +56,7 @@ struct sd_dhcp_client {
 struct ether_addr mac_addr;
 uint32_t xid;
 usec_t start_time;
+unsigned int attempt;
 DHCPLease *lease;
 };
 
@@ -151,6 +152,8 @@ static int client_stop(sd_dhcp_client *client, int error)
 
 client->timeout_resend = sd_event_source_unref(client->timeout_resend);
 
+client->attempt = 1;
+
 switch (client->state) {
 
 case DHCP_STATE_INIT:
@@ -252,6 +255,28 @@ static uint16_t client_checksum(void *buf, int len)
 return ~((sum & 0x) + (sum >> 16));
 }
 
+static void client_append_ip_headers(DHCPPacket *packet, uint16_t len)
+{
+packet->ip.version = IPVERSION;
+packet->ip.ihl = DHCP_IP_SIZE / 4;
+packet->ip.tot_len = htobe16(len);
+
+packet->ip.protocol = IPPROTO_UDP;
+packet->ip.saddr = INADDR_ANY;
+packet->ip.daddr = INADDR_BROADCAST;
+
+packet->udp.source = htobe16(DHCP_PORT_CLIENT);
+packet->udp.dest = htobe16(DHCP_PORT_SERVER);
+packet->udp.len = htobe16(len - DHCP_IP_SIZE);
+
+packet->ip.check = packet->udp.len;
+packet->udp.check = client_checksum(&packet->ip.ttl, len - 8);
+
+packet->ip.ttl = IPDEFTTL;
+packet->ip.check = 0;
+packet->ip.check = client_checksum(&packet->ip, DHCP_IP_SIZE);
+}
+
 static int client_send_discover(sd_dhcp_client *client, uint16_t secs)
 {
 int err = 0;
@@ -284,29 +309,55 @@ static int client_send_discover(sd_dhcp_client *client, 
uint16_t secs)
 if (err < 0)
 return err;
 
-discover->ip.version = IPVERSION;
-discover->ip.ihl = sizeof(discover->ip) >> 2;
-discover->ip.tot_len = htobe16(len);
+client_append_ip_headers(discover, len);
+
+err = dhcp_network_send_raw_socket(client->fd, &client->link,
+   discover, len);
+
+return err;
+}
+
+static int client_send_request(sd_dhcp_client *client, uint16_t secs)
+{
+_cleanup_free_ DHCPPacket *request;
+size_t optlen, len;
+int err;
+uint8_t *opt;
+
+optlen = DHCP_CLIENT_MIN_OPTIONS_SIZE;
+len = DHCP_MESSAGE_SIZE + optlen;
+
+request = malloc0(len);
+if (!request)
+return -ENOMEM;
+
+err = client_packet_init(client, DHCP_REQUEST, &request->dhcp, secs,
+ &opt, &optlen);
+if (err < 0)
+return err;
 
-discover->ip.protocol = IPPROTO_UDP;
-discover->ip.saddr = INADDR_ANY;
-discover->ip.daddr = INADDR_BROADCAST;
+if (client->state == DHCP_STATE_REQUESTING) {
+err = dhcp_option_append(&opt, &optlen,
+ DHCP_OPTION_REQUESTED_IP_ADDRESS,
+ 4, &client->lease->address);
+if (err < 0)
+return err;
 
-discover->udp.source = htobe16(DHCP_PORT_CLIENT);
-discover->udp.dest = htobe16(DHCP_PORT_SERVER);
-discover->udp.len = htobe16(len - sizeof(discover->ip));
+err = dhcp_option_append(&opt, &optlen,
+ DHCP_OPTION_SERVER_IDENTIFIER,
+ 4, &client->lease->server_address);
+if (err < 0)
+return err;
+}
 
-discover->ip.check = discover->udp.len;
-discover->udp.check = client_checksum(&discover->ip.ttl,
-  len - 8);
+err = dhcp_option_append(&opt, &optlen, DHCP_OPTION_END, 0, NULL);
+if (err < 0)
+return err;
 
-discover->ip.ttl = IPDEFTTL;
-discover->ip.check = 0;
-discover->ip.check = client_checksum(&discover->ip,
- sizeof(discover->ip));
+client_append_ip_headers(request, len);
 
 err = dhcp_network_send_raw_socket(client->fd, &client->link,
-   discover, len);
+   request, len);
 
 return err;
 }
@@ -319,32 +370,50 @@ static int client_timeout_resend(sd_event_source *s, 
uint64_t usec,
 uint16_t secs;

[systemd-devel] [PATCH v3 17/26] dhcp: Add function to stop the DHCP client

2013-12-09 Thread Patrik Flykt
The client is stopped and brought back to its initial state.
---
 src/dhcp/client.c|   32 
 src/systemd/sd-dhcp-client.h |1 +
 2 files changed, 33 insertions(+)

diff --git a/src/dhcp/client.c b/src/dhcp/client.c
index 665f986..60a1b4c 100644
--- a/src/dhcp/client.c
+++ b/src/dhcp/client.c
@@ -119,6 +119,33 @@ int sd_dhcp_client_set_mac(sd_dhcp_client *client,
 return 0;
 }
 
+static int client_stop(sd_dhcp_client *client, int error)
+{
+assert_return(client, -EINVAL);
+assert_return(client->state != DHCP_STATE_INIT &&
+  client->state != DHCP_STATE_INIT_REBOOT, -EALREADY);
+
+switch (client->state) {
+
+case DHCP_STATE_INIT:
+case DHCP_STATE_SELECTING:
+
+client->state = DHCP_STATE_INIT;
+break;
+
+case DHCP_STATE_INIT_REBOOT:
+case DHCP_STATE_REBOOTING:
+case DHCP_STATE_REQUESTING:
+case DHCP_STATE_BOUND:
+case DHCP_STATE_RENEWING:
+case DHCP_STATE_REBINDING:
+
+break;
+}
+
+return 0;
+}
+
 static int client_packet_init(sd_dhcp_client *client, uint8_t type,
   DHCPMessage *message, uint16_t secs,
   uint8_t **opt, size_t *optlen)
@@ -263,6 +290,11 @@ int sd_dhcp_client_start(sd_dhcp_client *client)
 return client_send_discover(client, 0);
 }
 
+int sd_dhcp_client_stop(sd_dhcp_client *client)
+{
+return client_stop(client, 0);
+}
+
 sd_dhcp_client *sd_dhcp_client_new(void)
 {
 sd_dhcp_client *client;
diff --git a/src/systemd/sd-dhcp-client.h b/src/systemd/sd-dhcp-client.h
index acfa3fa..2d2fdff 100644
--- a/src/systemd/sd-dhcp-client.h
+++ b/src/systemd/sd-dhcp-client.h
@@ -34,6 +34,7 @@ int sd_dhcp_client_set_index(sd_dhcp_client *client, int 
interface_index);
 int sd_dhcp_client_set_mac(sd_dhcp_client *client,
const struct ether_addr *addr);
 
+int sd_dhcp_client_stop(sd_dhcp_client *client);
 int sd_dhcp_client_start(sd_dhcp_client *client);
 sd_dhcp_client *sd_dhcp_client_new(void);
 
-- 
1.7.10.4

___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] [PATCH v3 15/26] dhcp: Add test for discover DHCP packet creation

2013-12-09 Thread Patrik Flykt
Set a fake MAC address and emulate raw packet sending. When the buffer
containing the Discover message is received, check selected IP and
UDP headers and compute IP header and UDP message checksums. Also
send the DHCP message for option parsing and expect a successful
outcome.
---
 Makefile.am |3 ++
 src/dhcp/test-dhcp-client.c |   80 +++
 2 files changed, 83 insertions(+)

diff --git a/Makefile.am b/Makefile.am
index cface06..1b9edf2 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -3869,6 +3869,9 @@ test_dhcp_option_LDADD = \
 test_dhcp_client_SOURCES = \
src/dhcp/protocol.h \
src/systemd/sd-dhcp-client.h \
+   src/dhcp/internal.h \
+   src/dhcp/option.h \
+   src/dhcp/option.c \
src/dhcp/client.c \
src/dhcp/test-dhcp-client.c
 
diff --git a/src/dhcp/test-dhcp-client.c b/src/dhcp/test-dhcp-client.c
index b226d3f..2e6b732 100644
--- a/src/dhcp/test-dhcp-client.c
+++ b/src/dhcp/test-dhcp-client.c
@@ -24,9 +24,16 @@
 #include 
 #include 
 
+#include "util.h"
+
 #include "protocol.h"
+#include "internal.h"
 #include "sd-dhcp-client.h"
 
+static struct ether_addr mac_addr = {
+.ether_addr_octet = {'A', 'B', 'C', '1', '2', '3'}
+};
+
 static void test_request_basic(void)
 {
 sd_dhcp_client *client;
@@ -112,10 +119,83 @@ static void test_checksum(void)
 assert(client_checksum(&buf, 20) == *val);
 }
 
+static int check_options(uint8_t code, uint8_t len, const uint8_t *option,
+void *user_data)
+{
+return 0;
+}
+
+int dhcp_network_send_raw_packet(int index, const void *packet, size_t len)
+{
+size_t size;
+_cleanup_free_ DHCPPacket *discover;
+uint16_t ip_check, udp_check;
+int res;
+
+assert(index == 42);
+assert(packet);
+
+size = sizeof(DHCPPacket) + 4;
+assert(len > size);
+
+discover = memdup(packet, len);
+
+assert(memcmp(discover->dhcp.chaddr,
+  &mac_addr.ether_addr_octet, 6) == 0);
+assert(discover->ip.ttl == IPDEFTTL);
+assert(discover->ip.protocol == IPPROTO_UDP);
+assert(discover->ip.saddr == INADDR_ANY);
+assert(discover->ip.daddr == INADDR_BROADCAST);
+assert(discover->udp.source == ntohs(DHCP_PORT_CLIENT));
+assert(discover->udp.dest == ntohs(DHCP_PORT_SERVER));
+
+ip_check = discover->ip.check;
+
+discover->ip.ttl = 0;
+discover->ip.check = discover->udp.len;
+
+udp_check = ~client_checksum(&discover->ip.ttl, len - 8);
+assert(udp_check == 0x);
+
+discover->ip.ttl = IPDEFTTL;
+discover->ip.check = ip_check;
+
+ip_check = ~client_checksum(&discover->ip, sizeof(discover->ip));
+assert(ip_check == 0x);
+
+size = len - sizeof(struct iphdr) - sizeof(struct udphdr);
+
+res = dhcp_option_parse(&discover->dhcp, size, check_options, NULL);
+if (res < 0)
+return res;
+
+return 575;
+}
+
+static void test_discover_message(void)
+{
+sd_dhcp_client *client;
+int res;
+
+client = sd_dhcp_client_new();
+assert(client);
+
+assert(sd_dhcp_client_set_index(client, 42) >= 0);
+assert(sd_dhcp_client_set_mac(client, &mac_addr) >= 0);
+
+assert(sd_dhcp_client_set_request_option(client, 248) >= 0);
+
+res = sd_dhcp_client_start(client);
+
+assert(res == 0 || res == -EINPROGRESS);
+}
+
 int main(int argc, char *argv[])
 {
 test_request_basic();
 test_checksum();
 
+test_discover_message();
+
 return 0;
 }
-- 
1.7.10.4

___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] [PATCH v3 04/26] build: Add initial build support

2013-12-09 Thread Patrik Flykt
The client test program is the only one to be built so far.
---
 Makefile.am   |   13 +
 src/dhcp/Makefile |1 +
 2 files changed, 14 insertions(+)
 create mode 12 src/dhcp/Makefile

diff --git a/Makefile.am b/Makefile.am
index 7bedd76..4e13370 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -3837,6 +3837,19 @@ lib_LTLIBRARIES += \
 endif
 
 # 
--
+test_dhcp_client_SOURCES = \
+   src/dhcp/protocol.h \
+   src/systemd/sd-dhcp-client.h \
+   src/dhcp/client.c \
+   src/dhcp/test-dhcp-client.c
+
+test_dhcp_client_LDADD = \
+   libsystemd-shared.la
+
+tests += \
+   test-dhcp-client
+
+# 
--
 if ENABLE_MACHINED
 systemd_machined_SOURCES = \
src/machine/machined.c \
diff --git a/src/dhcp/Makefile b/src/dhcp/Makefile
new file mode 12
index 000..d0b0e8e
--- /dev/null
+++ b/src/dhcp/Makefile
@@ -0,0 +1 @@
+../Makefile
\ No newline at end of file
-- 
1.7.10.4

___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] [PATCH v3 05/26] dhcp: Add option appending and parsing

2013-12-09 Thread Patrik Flykt
Add functions to append and parse DHCP options. Not all options
are passed to the callback function, the ones not exposed are
pad, end, message type and overload. If indicated by the overload
option, file and sname fields will be examined for more options.

The option functions are internal to DHCP, add a new header files
for interal function prototypes.
---
v3: use size_t for sizes, uint8_t for message_type, set buffer to const

 src/dhcp/internal.h |   34 ++
 src/dhcp/option.c   |  184 +++
 2 files changed, 218 insertions(+)
 create mode 100644 src/dhcp/internal.h
 create mode 100644 src/dhcp/option.c

diff --git a/src/dhcp/internal.h b/src/dhcp/internal.h
new file mode 100644
index 000..88e1a08
--- /dev/null
+++ b/src/dhcp/internal.h
@@ -0,0 +1,34 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+#pragma once
+
+/***
+  This file is part of systemd.
+
+  Copyright (C) 2013 Intel Corporation. All rights reserved.
+
+  systemd is free software; you can redistribute it and/or modify it
+  under the terms of the GNU Lesser General Public License as published by
+  the Free Software Foundation; either version 2.1 of the License, or
+  (at your option) any later version.
+
+  systemd 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
+  Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public License
+  along with systemd; If not, see .
+***/
+
+#include 
+
+#include "protocol.h"
+
+int dhcp_option_append(uint8_t **buf, size_t *buflen, uint8_t code,
+   size_t optlen, const void *optval);
+
+typedef int (*dhcp_option_cb_t)(uint8_t code, uint8_t len,
+const uint8_t *option, void *user_data);
+int dhcp_option_parse(DHCPMessage *message, size_t len,
+  dhcp_option_cb_t cb, void *user_data);
diff --git a/src/dhcp/option.c b/src/dhcp/option.c
new file mode 100644
index 000..235b387
--- /dev/null
+++ b/src/dhcp/option.c
@@ -0,0 +1,184 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+/***
+  This file is part of systemd.
+
+  Copyright (C) 2013 Intel Corporation. All rights reserved.
+
+  systemd is free software; you can redistribute it and/or modify it
+  under the terms of the GNU Lesser General Public License as published by
+  the Free Software Foundation; either version 2.1 of the License, or
+  (at your option) any later version.
+
+  systemd 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
+  Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public License
+  along with systemd; If not, see .
+***/
+
+#include 
+#include 
+#include 
+#include 
+
+#include "internal.h"
+
+int dhcp_option_append(uint8_t **buf, size_t *buflen, uint8_t code,
+   size_t optlen, const void *optval)
+{
+if (!buf || !buflen)
+return -EINVAL;
+
+switch (code) {
+
+case DHCP_OPTION_PAD:
+case DHCP_OPTION_END:
+if (*buflen < 1)
+return -ENOBUFS;
+
+(*buf)[0] = code;
+*buf += 1;
+*buflen -= 1;
+break;
+
+default:
+if (*buflen < optlen + 2)
+return -ENOBUFS;
+
+if (!optval)
+return -EINVAL;
+
+(*buf)[0] = code;
+(*buf)[1] = optlen;
+memcpy(&(*buf)[2], optval, optlen);
+
+*buf += optlen + 2;
+*buflen -= (optlen + 2);
+
+break;
+}
+
+return 0;
+}
+
+static int parse_options(const uint8_t *buf, size_t buflen, uint8_t *overload,
+ uint8_t *message_type, dhcp_option_cb_t cb,
+ void *user_data)
+{
+const uint8_t *code = buf;
+const uint8_t *len;
+
+while (buflen > 0) {
+switch (*code) {
+case DHCP_OPTION_PAD:
+buflen -= 1;
+code++;
+break;
+
+case DHCP_OPTION_END:
+return 0;
+
+case DHCP_OPTION_MESSAGE_TYPE:
+if (buflen < 3)
+return -ENOBUFS;
+buflen -= 3;
+
+len = code + 1;
+if (*len != 1)
+return -EINVAL;
+
+if (message_type)
+   

[systemd-devel] [PATCH v3 10/26] dhcp: Add test function for computing checksum

2013-12-09 Thread Patrik Flykt
---
 src/dhcp/test-dhcp-client.c |   40 
 1 file changed, 40 insertions(+)

diff --git a/src/dhcp/test-dhcp-client.c b/src/dhcp/test-dhcp-client.c
index cb2f652..b226d3f 100644
--- a/src/dhcp/test-dhcp-client.c
+++ b/src/dhcp/test-dhcp-client.c
@@ -22,6 +22,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "protocol.h"
 #include "sd-dhcp-client.h"
@@ -73,9 +74,48 @@ static void test_request_basic(void)
 assert(sd_dhcp_client_set_request_option(client, 44) == 0);
 }
 
+static uint16_t client_checksum(void *buf, int len)
+{
+uint32_t sum;
+uint16_t *check;
+int i;
+uint8_t *odd;
+
+sum = 0;
+check = buf;
+
+for (i = 0; i < len / 2 ; i++)
+sum += check[i];
+
+if (len & 0x01) {
+odd = buf;
+sum += odd[len];
+}
+
+return ~((sum & 0x) + (sum >> 16));
+}
+
+static void test_checksum(void)
+{
+uint8_t buf[20] = {
+0x45, 0x00, 0x02, 0x40, 0x00, 0x00, 0x00, 0x00,
+0x40, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+0xff, 0xff, 0xff, 0xff
+};
+
+uint8_t check[2] = {
+0x78, 0xae
+};
+
+uint16_t *val = (uint16_t *)check;
+
+assert(client_checksum(&buf, 20) == *val);
+}
+
 int main(int argc, char *argv[])
 {
 test_request_basic();
+test_checksum();
 
 return 0;
 }
-- 
1.7.10.4

___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] [PATCH v3 00/26] Initial DHCP v4 library implementation

2013-12-09 Thread Patrik Flykt
Hi,

Here is version 3 fixed according to comments plus a few identical ones
found in the code.

Essential changes are unconditionally compiling the DHCP code and re-adding
the sd_dhcp_client_get_netmask() function due to popular demand. Prefix
length computation is turned into a support function instead.

The timer problem was solved, the timer callback function gets the supplied
timeout value, in this case zero, and thus it miscalculated any further
timer values causing them all to trigger "immediately".

A proper directory should be selected for the code, currently it's still
the same old src/dhcp.


Cheers,

Patrik


Patrik Flykt (26):
  dhcp: Add DHCP protocol structures and initial defines
  dhcp: Add DHCP client initialization
  dhcp: Add test for DHCP client initialization and parameter setting
  build: Add initial build support
  dhcp: Add option appending and parsing
  dhcp: Add buffer length and invalid cookie tests for DHCP options
  build: Add DHCP option test
  dhcp: Add tests for DHCP options, file and sname fields
  dhcp: Add option append tests
  dhcp: Add test function for computing checksum
  shared: Add struct sockaddr_ll to sockaddr_union
  dhcp: Add function for sending a raw packet
  dhcp: Add DHCP discover sending
  build: Add libsystemd-dhcp
  dhcp: Add test for discover DHCP packet creation
  dhcp: Support seconds elapsed since start of DHCP negotiation
  dhcp: Add function to stop the DHCP client
  build: Add dependency on libsystemd-bus needed for main loop
  dhcp: Add timeout and main loop support
  dhcp: Handle received DHCP Offer message
  dhcp: Send DHCP Request to acquire an IP address
  dhcp: Add maximum message size option
  dhcp: Process DHCP Ack/Nak message
  dhcp: Compute expire, T1 and T2 timers
  dhcp: Add notification callback
  dhcp: Add function to free DHCP client data

 Makefile.am  |   48 ++
 src/dhcp/Makefile|1 +
 src/dhcp/client.c| 1002 ++
 src/dhcp/internal.h  |   41 ++
 src/dhcp/network.c   |   65 +++
 src/dhcp/option.c|  184 
 src/dhcp/protocol.h  |  119 +
 src/dhcp/test-dhcp-client.c  |  224 ++
 src/dhcp/test-dhcp-option.c  |  377 
 src/shared/socket-util.h |2 +
 src/systemd/sd-dhcp-client.h |   63 +++
 11 files changed, 2126 insertions(+)
 create mode 12 src/dhcp/Makefile
 create mode 100644 src/dhcp/client.c
 create mode 100644 src/dhcp/internal.h
 create mode 100644 src/dhcp/network.c
 create mode 100644 src/dhcp/option.c
 create mode 100644 src/dhcp/protocol.h
 create mode 100644 src/dhcp/test-dhcp-client.c
 create mode 100644 src/dhcp/test-dhcp-option.c
 create mode 100644 src/systemd/sd-dhcp-client.h

-- 
1.7.10.4

___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] [PATCH v2 00/26] Initial DHCP v4 library implementation

2013-12-09 Thread Patrik Flykt
On Mon, 2013-11-25 at 23:52 +0100, Lennart Poettering wrote:
> Of course, timer callbacks should only be called once, ence
> ONESHOT mode is the default -- unless you change that explicitly.
> 
> If this doesn't solve the issue, I wouldn't be surprised if there was
> still a bug lurking with the sd-event code. Note that I fixed a bug
> like this last week, did you check with currentl git of sd-event if
> the issue persists?

Found the source of this issue. When the (monotonic) timeout function is
called with time 0 meaning "immediately", the callback indeed gets
called next by the event loop. But the uint64_t usec value passed to the
timer callback is the value 0 set by the caller, not the current
monotonic time the callback is called at. Using the supplied usec value,
which is 0, as a base when calculating the next event timeout results of
course in a time very much smaller time than the current monotonic time,
causing the callback to be called immediately again. The value is again
the one set by the caller and thus the calculated time is again too low.
Rinse and repeat.

I fixed the problem by using sd_event_get_now_monotonic() instead of the
supplied usec value as it wasn't clear what the intended behavior was.
systemd upstream version tested was from approximately last Friday
should something have changed recently.

Cheers,

Patrik


___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] [PATCH] test: rework run_qemu

2013-12-09 Thread Ronny Chevalier
Do we really want to add a compat for several distributions ? Because
why not Archlinux, Ubuntu,... too ?
I used Fedora's path by default because it was in the previous script.

2013/12/8 Shawn Landden :
> On Sat, Dec 7, 2013 at 3:01 PM, Ronny Chevalier
>  wrote:
>> It tries to find a suitable QEMU binary and will use KVM if present.
>> We can now configure QEMU from outside with 4 variables :
>>   - $QEMU_BIN : path to QEMU's binary
>>   - $KERNEL_APPEND : arguments appended to kernel cmdline
>>   - $KERNEL_BIN : path to a kernel
>> Default /boot/vmlinuz-$KERNEL_VER
>>   - $INITRD : path to an initramfs
>> Default /boot/initramfs-${KERNEL_VER}.img
>>   - $QEMU_SMP : number of CPU simulated by QEMU.
>> Default 1
>>
>> (from Alexander Graf's script: 
>> http://www.spinics.net/lists/kvm/msg72389.html)
>> ---
>>  TODO|  1 -
>>  test/README.testsuite   | 19 ++--
>>  test/TEST-01-BASIC/test.sh  |  8 ++---
>>  test/TEST-02-CRYPTSETUP/test.sh |  8 ++---
>>  test/TEST-03-JOBS/test.sh   |  8 ++---
>>  test/test-functions | 65 
>> +++--
>>  6 files changed, 78 insertions(+), 31 deletions(-)
>>
>> diff --git a/TODO b/TODO
>> index 9698082..f493dbb 100644
>> --- a/TODO
>> +++ b/TODO
>> @@ -168,7 +168,6 @@ Features:
>>  * test/:
>>- add 'set -e' to scripts in test/
>>- make stuff in test/ work with separate output dir
>> -  - qemu wrapper script: http://www.spinics.net/lists/kvm/msg72389.html
>>
>>  * systemctl delete x.snapshot leaves no trace in logs (at least at default 
>> level).
>>
>> diff --git a/test/README.testsuite b/test/README.testsuite
>> index 54d0eaa..2ae85a2 100644
>> --- a/test/README.testsuite
>> +++ b/test/README.testsuite
>> @@ -25,11 +25,24 @@ $ make all
>>  $ cd test/TEST-01-BASIC
>>  $ sudo make clean setup run
>>
>> +QEMU
>> +
>> +
>>  If you want to log in the testsuite virtual machine, you can specify
>> -additional kernel command line parameter with $DEBUGFAIL.
>> +additional kernel command line parameter with $KERNEL_APPEND.
>>
>> -$ sudo make DEBUGFAIL="systemd.unit=multi-user.target" clean setup run
>> +$ sudo make KERNEL_APPEND="systemd.unit=multi-user.target" clean setup run
>>
>>  you can even skip the "clean" and "setup" if you want to run the machine 
>> again.
>>
>> -$ sudo make DEBUGFAIL="systemd.unit=multi-user.target" run
>> +$ sudo make KERNEL_APPEND="systemd.unit=multi-user.target" run
>> +
>> +You can specify a different kernel and initramfs with $KERNEL_BIN and 
>> $INITRD.
>> +(Fedora's default kernel path and initramfs are used by default)
>> +
>> +$ sudo make KERNEL_BIN=/boot/vmlinuz-foo INITRD=/boot/initramfs-bar clean 
>> check
>> +
>> +A script will try to find your QEMU binary. If you want to specify a 
>> different
>> +one you can use $QEMU_BIN.
>> +
>> +$ sudo make QEMU_BIN=/path/to/qemu/qemu-kvm clean check
>> diff --git a/test/TEST-01-BASIC/test.sh b/test/TEST-01-BASIC/test.sh
>> index aaf63f4..84ccf26 100755
>> --- a/test/TEST-01-BASIC/test.sh
>> +++ b/test/TEST-01-BASIC/test.sh
>> @@ -5,9 +5,6 @@ TEST_DESCRIPTION="Basic systemd setup"
>>
>>  . $TEST_BASE_DIR/test-functions
>>
>> -# Uncomment this to debug failures
>> -#DEBUGFAIL="systemd.unit=multi-user.target"
>> -
>>  check_result_qemu() {
>>  ret=1
>>  mkdir -p $TESTDIR/root
>> @@ -23,11 +20,10 @@ check_result_qemu() {
>>  }
>>
>>  test_run() {
>> -if check_qemu ; then
>> -run_qemu
>> +if run_qemu; then
>>  check_result_qemu || return 1
>>  else
>> -dwarn "can't run qemu-kvm, skipping"
>> +dwarn "can't run QEMU, skipping"
>>  fi
>>  if check_nspawn; then
>>  run_nspawn
>> diff --git a/test/TEST-02-CRYPTSETUP/test.sh 
>> b/test/TEST-02-CRYPTSETUP/test.sh
>> index 86617df..d7e8776 100755
>> --- a/test/TEST-02-CRYPTSETUP/test.sh
>> +++ b/test/TEST-02-CRYPTSETUP/test.sh
>> @@ -5,9 +5,6 @@ TEST_DESCRIPTION="cryptsetup systemd setup"
>>
>>  . $TEST_BASE_DIR/test-functions
>>
>> -# Uncomment this to debug failures
>> -#DEBUGFAIL="systemd.unit=multi-user.target"
>> -
>>  check_result_qemu() {
>>  ret=1
>>  mkdir -p $TESTDIR/root
>> @@ -28,11 +25,10 @@ check_result_qemu() {
>>
>>
>>  test_run() {
>> -if check_qemu ; then
>> -run_qemu
>> +if run_qemu; then
>>  check_result_qemu || return 1
>>  else
>> -dwarn "can't run qemu-kvm, skipping"
>> +dwarn "can't run QEMU, skipping"
>>  fi
>>  return 0
>>  }
>> diff --git a/test/TEST-03-JOBS/test.sh b/test/TEST-03-JOBS/test.sh
>> index 6303258..41e02e2 100755
>> --- a/test/TEST-03-JOBS/test.sh
>> +++ b/test/TEST-03-JOBS/test.sh
>> @@ -5,9 +5,6 @@ TEST_DESCRIPTION="Job-related tests"
>>
>>  . $TEST_BASE_DIR/test-functions
>>
>> -# Uncomment this to debug failures
>> -#DEBUGFAIL="systemd.unit=multi-user.target"
>> -
>>  check_result_qemu() {
>>  ret=1
>>  mkdir -p $TESTDIR/root
>> @@ -23,11 +20,10 @@ check_result_qemu() {
>> 

Re: [systemd-devel] [PATCH] libsystemd-bus: Clean up code

2013-12-09 Thread Thomas H.P. Andersen
If I understood correctly then the assert_return was meant to be used
only on the public library functions. I can't seem to find the
reference to it so maybe I am wrong though.

On Mon, Dec 9, 2013 at 2:09 PM, Lukasz Skalski
 wrote:
> ---
>  src/libsystemd-bus/bus-dump.c  |  2 +-
>  src/libsystemd-bus/bus-error.c |  3 +--
>  src/libsystemd-bus/bus-kernel.c| 12 +++-
>  src/libsystemd-bus/bus-message.c   | 12 +++-
>  src/libsystemd-bus/bus-signature.c | 13 -
>  5 files changed, 12 insertions(+), 30 deletions(-)
>
> diff --git a/src/libsystemd-bus/bus-dump.c b/src/libsystemd-bus/bus-dump.c
> index ddad418..a999683 100644
> --- a/src/libsystemd-bus/bus-dump.c
> +++ b/src/libsystemd-bus/bus-dump.c
> @@ -56,7 +56,7 @@ int bus_message_dump(sd_bus_message *m, FILE *f, bool 
> with_header) {
>
>  if (with_header) {
>  fprintf(f,
> -"%s%s%sType=%s%s%s  Endian=%c  Flags=%u  Version=%u",
> +"%s%s%sType=%s%s%s  Endian=%c  Flags=%u  Version=%u 
> ",
>  m->header->type == SD_BUS_MESSAGE_METHOD_ERROR ? 
> ansi_highlight_red() :
>  m->header->type == SD_BUS_MESSAGE_METHOD_RETURN ? 
> ansi_highlight_green() :
>  m->header->type != SD_BUS_MESSAGE_SIGNAL ? 
> ansi_highlight() : "", draw_special_char(DRAW_TRIANGULAR_BULLET), 
> ansi_highlight_off(),
> diff --git a/src/libsystemd-bus/bus-error.c b/src/libsystemd-bus/bus-error.c
> index 25eaf0e..4f18629 100644
> --- a/src/libsystemd-bus/bus-error.c
> +++ b/src/libsystemd-bus/bus-error.c
> @@ -39,8 +39,7 @@ static int bus_error_name_to_errno(const char *name) {
>  const char *p;
>  int r;
>
> -if (!name)
> -return EINVAL;
> +assert_return(name, EINVAL);
>
>  p = startswith(name, "System.Error.");
>  if (p) {
> diff --git a/src/libsystemd-bus/bus-kernel.c b/src/libsystemd-bus/bus-kernel.c
> index 495d7e5..d5574ce 100644
> --- a/src/libsystemd-bus/bus-kernel.c
> +++ b/src/libsystemd-bus/bus-kernel.c
> @@ -321,9 +321,7 @@ int bus_kernel_take_fd(sd_bus *b) {
>  int r;
>
>  assert(b);
> -
> -if (b->is_server)
> -return -EINVAL;
> +assert_return(!b->is_server, -EINVAL);
>
>  b->use_memfd = 1;
>
> @@ -374,9 +372,7 @@ int bus_kernel_connect(sd_bus *b) {
>  assert(b->input_fd < 0);
>  assert(b->output_fd < 0);
>  assert(b->kernel);
> -
> -if (b->is_server)
> -return -EINVAL;
> +assert_return(!b->is_server, -EINVAL);
>
>  b->input_fd = open(b->kernel, O_RDWR|O_NOCTTY|O_CLOEXEC);
>  if (b->input_fd < 0)
> @@ -904,9 +900,7 @@ int bus_kernel_pop_memfd(sd_bus *bus, void **address, 
> size_t *size) {
>
>  assert(address);
>  assert(size);
> -
> -if (!bus || !bus->is_kernel)
> -return -ENOTSUP;
> +assert_return(bus || bus->is_kernel, -ENOTSUP);
You should && them here.

>  assert_se(pthread_mutex_lock(&bus->memfd_cache_mutex) >= 0);
>
> diff --git a/src/libsystemd-bus/bus-message.c 
> b/src/libsystemd-bus/bus-message.c
> index 4c0e27f..041dfba 100644
> --- a/src/libsystemd-bus/bus-message.c
> +++ b/src/libsystemd-bus/bus-message.c
> @@ -158,9 +158,7 @@ static void *message_extend_fields(sd_bus_message *m, 
> size_t align, size_t sz, b
>  size_t old_size, new_size, start;
>
>  assert(m);
> -
> -if (m->poisoned)
> -return NULL;
> +assert_return(!m->poisoned, NULL);
>
>  old_size = sizeof(struct bus_header) + m->header->fields_size;
>  start = ALIGN_TO(old_size, align);
> @@ -985,9 +983,7 @@ struct bus_body_part *message_append_part(sd_bus_message 
> *m) {
>  struct bus_body_part *part;
>
>  assert(m);
> -
> -if (m->poisoned)
> -return NULL;
> +assert_return(!m->poisoned, NULL);
>
>  if (m->n_body_parts <= 0) {
>  part = &m->body;
> @@ -1136,9 +1132,7 @@ static void *message_extend_body(sd_bus_message *m, 
> size_t align, size_t sz, boo
>  assert(m);
>  assert(align > 0);
>  assert(!m->sealed);
> -
> -if (m->poisoned)
> -return NULL;
> +assert_return(!m->poisoned, NULL);
>
>  start_body = ALIGN_TO((size_t) m->header->body_size, align);
>  end_body = start_body + sz;
> diff --git a/src/libsystemd-bus/bus-signature.c 
> b/src/libsystemd-bus/bus-signature.c
> index 1e5bf48..3fb0794 100644
> --- a/src/libsystemd-bus/bus-signature.c
> +++ b/src/libsystemd-bus/bus-signature.c
> @@ -33,9 +33,7 @@ static int signature_element_length_internal(
>
>  int r;
>
> -if (!s)
> -return -EINVAL;
> -
> +assert_return(s, -EINVAL);
>  assert(l);
>
>  if (bus_type_is_basic(*s) || *s == SD_BUS_TYPE_VARIANT) {
> @@ -117,8 +115,7 @@ bool si

[systemd-devel] [PATCH] fix scan-build issues

2013-12-09 Thread Thomas H.P. Andersen
From: Thomas Hindoe Paaboel Andersen 

The static analyzer scan-build had a few issues with analysing
parts of systemd.

gpt-auto-generator.c:
scan-build could not find blkid.h. Whether it should be blkid.h or
blkid/blkid.h seems to depend on the version used. We already use
blkid/blkid.h in udev-builtin-blkid.c so it seems safe to use that
here too.

Makefile.am:
Moved some -D's from CFLAGS to CPPFLAGS. I also simplified them a
bit and got rid of a left over DBUS_CFLAGS.
---
 Makefile.am | 22 --
 src/gpt-auto-generator/gpt-auto-generator.c |  2 +-
 2 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index 7bedd76..e90e7ed 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1349,10 +1349,9 @@ test_cgroup_LDADD = \
 test_cgroup_mask_SOURCES = \
src/test/test-cgroup-mask.c
 
-test_cgroup_mask_CFLAGS = \
-   $(AM_CFLAGS) \
-   $(DBUS_CFLAGS) \
-   -D"STR(s)=\#s" -D"TEST_DIR=STR($(abs_top_srcdir)/test/)"
+test_cgroup_mask_CPPFLAGS = \
+   $(AM_CPPFLAGS) \
+   -DTEST_DIR=\"$(abs_top_srcdir)/test\"
 
 test_cgroup_mask_LDADD = \
libsystemd-core.la \
@@ -1416,9 +1415,9 @@ test_watchdog_LDADD = \
 test_sched_prio_SOURCES = \
src/test/test-sched-prio.c
 
-test_sched_prio_CFLAGS = \
-   $(AM_CFLAGS) \
-   -D"STR(s)=\#s" -D"TEST_DIR=STR($(abs_top_srcdir)/test/)"
+test_sched_prio_CPPFLAGS = \
+   $(AM_CPPFLAGS) \
+   -DTEST_DIR=\"$(abs_top_srcdir)/test\"
 
 test_sched_prio_LDADD = \
libsystemd-core.la \
@@ -3054,8 +3053,8 @@ test_mmap_cache_LDADD = \
 test_catalog_SOURCES = \
src/journal/test-catalog.c
 
-test_catalog_CFLAGS = \
-   $(AM_CFLAGS) \
+test_catalog_CPPFLAGS = \
+   $(AM_CPPFLAGS) \
-DCATALOG_DIR=\"$(abs_top_srcdir)/catalog\"
 
 test_catalog_LDADD = \
@@ -3313,9 +3312,12 @@ systemd_journal_gatewayd_LDADD = \
 
 systemd_journal_gatewayd_CFLAGS = \
$(AM_CFLAGS) \
-   -DDOCUMENT_ROOT=\"$(gatewayddocumentrootdir)\" \
$(MICROHTTPD_CFLAGS)
 
+systemd_journal_gatewayd_CPPFLAGS = \
+   $(AM_CPPFLAGS) \
+   -DDOCUMENT_ROOT=\"$(gatewayddocumentrootdir)\"
+
 dist_systemunit_DATA += \
units/systemd-journal-gatewayd.socket
 
diff --git a/src/gpt-auto-generator/gpt-auto-generator.c 
b/src/gpt-auto-generator/gpt-auto-generator.c
index 3cbafa4..017c35d 100644
--- a/src/gpt-auto-generator/gpt-auto-generator.c
+++ b/src/gpt-auto-generator/gpt-auto-generator.c
@@ -24,7 +24,7 @@
 #include 
 #include 
 #include 
-#include 
+#include 
 
 #ifdef HAVE_LINUX_BTRFS_H
 #include 
-- 
1.8.4.2

___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] user@.service doesn't stop on logout

2013-12-09 Thread Thomas Bächler
In systemd 208 and latest systemd git, every user gets a new
user@.service instance when they login. However, when their last session
exits, that service is not terminated.

After a few weeks of uptime on one of my servers, dozens of
user@.service units are running, belonging to users that logged in weeks
ago and haven't been seen since. Is this really the intended behaviour?

Random screenshot: https://paste.xinu.at/RZn/



signature.asc
Description: OpenPGP digital signature
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] udevadm settle takes too long to finish

2013-12-09 Thread Chris Murphy

On Dec 9, 2013, at 3:33 AM, Thomas Bächler  wrote:

> Am 07.12.2013 22:29, schrieb Robert Milasan:
>> From systemd-analyze dump:
>> 
>>Wants: systemd-udevd.service
>>WantedBy: lvm2-activation-early.service
>>WantedBy: lvm2-activation.service
>>Before: lvm2-activation-early.service
>>Before: sysinit.target
>>After: systemd-udev-trigger.service
>>After: systemd-journald.socket
>>References: systemd-udevd.service
>>References: systemd-udev-trigger.service
>>References: sysinit.target
>>References: systemd-journald.socket
>>ReferencedBy: lvm2-activation-early.service
>>ReferencedBy: lvm2-activation.service
> 
> What's the distribution you are using? Using udevadm settle for lvm is a
> waste of boot time and isn't even guaranteed to work (ask Lennart, Kay
> or Greg K-H for the full speech). It's a hackish workaround for LVM's
> inability to activate volumes automatically.

I'm finding that plymouth-start.service uses ExecStartPost= to call udevadm 
settle twice.

The actual culprit though is dmraid-activation.service which is enabled by 
default (why?) and Wants=systemd-udev-settle.service. dmraid.activation.service 
also has the #2 biggest blame hit:
4.551s dmraid-activation.service

So why is this enabled by default when there's no dmraid at all, and never has 
been dmraid metadata on any attached device?

If I systemctl disable dmraid-activation.service both the 
dmraid-activation.service hit goes away, as does systemd-udev-settle.service.


Chris Murphy
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] Setting low-level cgroups attributes in systemd

2013-12-09 Thread Joe Miller
It appears that the .slice changed described here[1] removed all ability to
set low-level cgroups settings, is that correct?

For cgroup attributes that systemd does not natively support
(example: cpu.cfs_period_us and cpu.cfs_quota_us) it was previously
possible to set these

1. via unit files:  ControlGroupAttribute=cpu.cfs_period_us 500
2. or at runtime:  systemctl --runtime set-cgroup-attr thing.service
cpu.cfs_period_us 500

I find the ability to set cgroup attrs not supported natively by systemd
useful, will this be added back to systemd or will systemd support all
cgroup attributes?


[1] - https://lwn.net/Articles/555923/
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] [PATCH 4/4] core: lazy distribute for Distribute pools

2013-12-09 Thread David Timothy Strauss
On Sun, Dec 8, 2013 at 8:25 PM, Shawn Landden  wrote:
> This one doesn't work. I have have a somewhat-working next patch, but
> the way epoll_wait works it actually isn't
> lazy at all, and would require EPOLLET to even do
> one-spawn-per-connection (global connection), but we can't
> do that with the current event loop. I ended up getting side-tracked
> into adding mount-namespace to
> lsof, cause i noticed that feature lacking while working on this
>
> Anyways, a new series will come, and I am working on it.

Why don't we just start with an eagerly spawned pool? We can always
add lazy support later.
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] systemd-nspawn and kernel command line

2013-12-09 Thread Colin Guthrie
'Twas brillig, and Lennart Poettering at 08/12/13 23:48 did gyre and gimble:
> On Sat, 07.12.13 18:33, Colin Guthrie (gm...@colin.guthr.ie) wrote:
> 
>> Hi,
>>
>> When playing with systemd-nspawn, is there a way to override the kernel
>> command line seen inside the container. I mean it's probably not correct
>> that the host systems /proc/cmdline leaks into the container.
> 
> Most of systemd's own code actually knows this, and will ignore
> /proc/cmdline if it detects that it is being run in a container. (I
> recently unified this checking in util.c's proc_cmdline() call, so that
> we don't forget to check this by mistake somewhere).
> 
> Where di you run into problems with this?

We I was thinking it was preventing the container from booting
properly as we booted our host with "rescue" in the command line, but
thinking about it more, the container seems to make it to multi-user
target just fine... it should be defaulting to graphical.target (that's
what the default.target symlink points to at least) but that doesn't
kick in... not looking into why but I kinda *want* it to be
multi-user.target for debugging anyway, so not too upset about that.

So I think my "problem case" might actually be invalid, but glad I came
up with a nice idea in the process ;)

Col

-- 

Colin Guthrie
gmane(at)colin.guthr.ie
http://colin.guthr.ie/

Day Job:
  Tribalogic Limited http://www.tribalogic.net/
Open Source:
  Mageia Contributor http://www.mageia.org/
  PulseAudio Hacker http://www.pulseaudio.org/
  Trac Hacker http://trac.edgewall.org/

___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] [PATCH] update README to not suggest that systemd works without procfs

2013-12-09 Thread Shawn Landden
---
 README | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/README b/README
index cc43953..7cd1f1d 100644
--- a/README
+++ b/README
@@ -45,6 +45,7 @@ REQUIREMENTS:
   CONFIG_EPOLL
   CONFIG_NET
   CONFIG_SYSFS
+  CONFIG_PROC_FS
 
 Linux kernel >= 3.8 for Smack support
 
@@ -75,9 +76,7 @@ REQUIREMENTS:
   CONFIG_TMPFS_XATTR
   CONFIG_SECCOMP
 
-For systemd-bootchart, a kernel with procfs support and
-several proc output options enabled is required:
-  CONFIG_PROC_FS
+For systemd-bootchart, several proc debug interfaces are required:
   CONFIG_SCHEDSTATS
   CONFIG_SCHED_DEBUG
 
-- 
1.8.5.1

___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] [PATCH] update README to not suggest that systemd works without procfs

2013-12-09 Thread Shawn Landden
---
 README | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/README b/README
index cc43953..f2a86c5 100644
--- a/README
+++ b/README
@@ -45,6 +45,7 @@ REQUIREMENTS:
   CONFIG_EPOLL
   CONFIG_NET
   CONFIG_SYSFS
+  CONFIG_PROC_FS
 
 Linux kernel >= 3.8 for Smack support
 
@@ -75,9 +76,7 @@ REQUIREMENTS:
   CONFIG_TMPFS_XATTR
   CONFIG_SECCOMP
 
-For systemd-bootchart, a kernel with procfs support and
-several proc output options enabled is required:
-  CONFIG_PROC_FS
+For systemd-bootchar, several proc debug interfaces are required:
   CONFIG_SCHEDSTATS
   CONFIG_SCHED_DEBUG
 
-- 
1.8.5.1

___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] Question about a udev rule

2013-12-09 Thread Kay Sievers
On Mon, Dec 9, 2013 at 8:08 AM, Hannes Reinecke  wrote:
> On 12/08/2013 07:14 PM, Robert Milasan wrote:

> 1) udev rules deal with single events only. So all information for
> the current event is directly available (set in environment
> variables etc), and there is no need to call 'udevadm info'

That's right. --device-id-of-file= though, is just a "smarter" stat,
and does not look at udev's data.

> 2) For cross-event mechanisms (ie if you need to synchronize
> between several events) you should be using appropriate
> mechanisms like collect.
>
> And the 'root' symlink is generated directly by dracut; maybe you
> should look there ...

/dev/root is dead in userspace, also in dracut, it will not come back.
:) Just port the tools to the present, and do not require it, btrfs
can never have /dev/root anyway.

Kay
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] [PATCH] libsystemd-bus: Clean up code

2013-12-09 Thread Lukasz Skalski
---
 src/libsystemd-bus/bus-dump.c  |  2 +-
 src/libsystemd-bus/bus-error.c |  3 +--
 src/libsystemd-bus/bus-kernel.c| 12 +++-
 src/libsystemd-bus/bus-message.c   | 12 +++-
 src/libsystemd-bus/bus-signature.c | 13 -
 5 files changed, 12 insertions(+), 30 deletions(-)

diff --git a/src/libsystemd-bus/bus-dump.c b/src/libsystemd-bus/bus-dump.c
index ddad418..a999683 100644
--- a/src/libsystemd-bus/bus-dump.c
+++ b/src/libsystemd-bus/bus-dump.c
@@ -56,7 +56,7 @@ int bus_message_dump(sd_bus_message *m, FILE *f, bool 
with_header) {
 
 if (with_header) {
 fprintf(f,
-"%s%s%sType=%s%s%s  Endian=%c  Flags=%u  Version=%u",
+"%s%s%sType=%s%s%s  Endian=%c  Flags=%u  Version=%u ",
 m->header->type == SD_BUS_MESSAGE_METHOD_ERROR ? 
ansi_highlight_red() :
 m->header->type == SD_BUS_MESSAGE_METHOD_RETURN ? 
ansi_highlight_green() :
 m->header->type != SD_BUS_MESSAGE_SIGNAL ? 
ansi_highlight() : "", draw_special_char(DRAW_TRIANGULAR_BULLET), 
ansi_highlight_off(),
diff --git a/src/libsystemd-bus/bus-error.c b/src/libsystemd-bus/bus-error.c
index 25eaf0e..4f18629 100644
--- a/src/libsystemd-bus/bus-error.c
+++ b/src/libsystemd-bus/bus-error.c
@@ -39,8 +39,7 @@ static int bus_error_name_to_errno(const char *name) {
 const char *p;
 int r;
 
-if (!name)
-return EINVAL;
+assert_return(name, EINVAL);
 
 p = startswith(name, "System.Error.");
 if (p) {
diff --git a/src/libsystemd-bus/bus-kernel.c b/src/libsystemd-bus/bus-kernel.c
index 495d7e5..d5574ce 100644
--- a/src/libsystemd-bus/bus-kernel.c
+++ b/src/libsystemd-bus/bus-kernel.c
@@ -321,9 +321,7 @@ int bus_kernel_take_fd(sd_bus *b) {
 int r;
 
 assert(b);
-
-if (b->is_server)
-return -EINVAL;
+assert_return(!b->is_server, -EINVAL);
 
 b->use_memfd = 1;
 
@@ -374,9 +372,7 @@ int bus_kernel_connect(sd_bus *b) {
 assert(b->input_fd < 0);
 assert(b->output_fd < 0);
 assert(b->kernel);
-
-if (b->is_server)
-return -EINVAL;
+assert_return(!b->is_server, -EINVAL);
 
 b->input_fd = open(b->kernel, O_RDWR|O_NOCTTY|O_CLOEXEC);
 if (b->input_fd < 0)
@@ -904,9 +900,7 @@ int bus_kernel_pop_memfd(sd_bus *bus, void **address, 
size_t *size) {
 
 assert(address);
 assert(size);
-
-if (!bus || !bus->is_kernel)
-return -ENOTSUP;
+assert_return(bus || bus->is_kernel, -ENOTSUP);
 
 assert_se(pthread_mutex_lock(&bus->memfd_cache_mutex) >= 0);
 
diff --git a/src/libsystemd-bus/bus-message.c b/src/libsystemd-bus/bus-message.c
index 4c0e27f..041dfba 100644
--- a/src/libsystemd-bus/bus-message.c
+++ b/src/libsystemd-bus/bus-message.c
@@ -158,9 +158,7 @@ static void *message_extend_fields(sd_bus_message *m, 
size_t align, size_t sz, b
 size_t old_size, new_size, start;
 
 assert(m);
-
-if (m->poisoned)
-return NULL;
+assert_return(!m->poisoned, NULL);
 
 old_size = sizeof(struct bus_header) + m->header->fields_size;
 start = ALIGN_TO(old_size, align);
@@ -985,9 +983,7 @@ struct bus_body_part *message_append_part(sd_bus_message 
*m) {
 struct bus_body_part *part;
 
 assert(m);
-
-if (m->poisoned)
-return NULL;
+assert_return(!m->poisoned, NULL);
 
 if (m->n_body_parts <= 0) {
 part = &m->body;
@@ -1136,9 +1132,7 @@ static void *message_extend_body(sd_bus_message *m, 
size_t align, size_t sz, boo
 assert(m);
 assert(align > 0);
 assert(!m->sealed);
-
-if (m->poisoned)
-return NULL;
+assert_return(!m->poisoned, NULL);
 
 start_body = ALIGN_TO((size_t) m->header->body_size, align);
 end_body = start_body + sz;
diff --git a/src/libsystemd-bus/bus-signature.c 
b/src/libsystemd-bus/bus-signature.c
index 1e5bf48..3fb0794 100644
--- a/src/libsystemd-bus/bus-signature.c
+++ b/src/libsystemd-bus/bus-signature.c
@@ -33,9 +33,7 @@ static int signature_element_length_internal(
 
 int r;
 
-if (!s)
-return -EINVAL;
-
+assert_return(s, -EINVAL);
 assert(l);
 
 if (bus_type_is_basic(*s) || *s == SD_BUS_TYPE_VARIANT) {
@@ -117,8 +115,7 @@ bool signature_is_single(const char *s, bool 
allow_dict_entry) {
 int r;
 size_t t;
 
-if (!s)
-return false;
+assert_return(s, false);
 
 r = signature_element_length_internal(s, allow_dict_entry, 0, 0, &t);
 if (r < 0)
@@ -129,8 +126,7 @@ bool signature_is_single(const char *s, bool 
allow_dict_entry) {
 
 bool signature_is_pair(const char *s) {
 
-if (!s)
-return false;
+assert_return(s, false);
 
  

Re: [systemd-devel] udevadm settle takes too long to finish

2013-12-09 Thread Robert Milasan
On Mon, 09 Dec 2013 11:33:03 +0100
"Thomas Bächler"  wrote:

> Am 07.12.2013 22:29, schrieb Robert Milasan:
> > From systemd-analyze dump:
> > 
> > Wants: systemd-udevd.service
> > WantedBy: lvm2-activation-early.service
> > WantedBy: lvm2-activation.service
> > Before: lvm2-activation-early.service
> > Before: sysinit.target
> > After: systemd-udev-trigger.service
> > After: systemd-journald.socket
> > References: systemd-udevd.service
> > References: systemd-udev-trigger.service
> > References: sysinit.target
> > References: systemd-journald.socket
> > ReferencedBy: lvm2-activation-early.service
> > ReferencedBy: lvm2-activation.service
> 
> What's the distribution you are using? Using udevadm settle for lvm
> is a waste of boot time and isn't even guaranteed to work (ask
> Lennart, Kay or Greg K-H for the full speech). It's a hackish
> workaround for LVM's inability to activate volumes automatically.
> 
> Instead, a socket-activated lvmetad service should be used in
> combination with the correct udev rules. The service files are
> provided by LVM, but they reference weird redhat-specific units and
> from what I saw have too many orderings, which results in slowing
> everything down needlessly.
> 
> Currently, I use 69-dm-lvm-metad.rules provided by LVM in combination
> with the unit files [1] and [2] (derived from the redhat units
> included in LVM). This is fast and works great for me, although
> lvmetad has some annoying bugs which have been reported to me, but
> which I could never reproduce.
> 
> There is no way to make udevadm settle "faster" and the only solution
> is (as Kay said already) is not using it.
> 
> [1]
> https://projects.archlinux.org/svntogit/packages.git/tree/trunk/lvmetad.service?h=packages/lvm2
> [2]
> https://projects.archlinux.org/svntogit/packages.git/tree/trunk/lvmetad.socket?h=packages/lvm2
> 

The distro is openSUSE and we are using lvm2-activation-generator which
comes with lvm2 package:

https://git.fedorahosted.org/cgit/lvm2.git/tree/scripts/lvm2_activation_generator_systemd_red_hat.c

-- 
Robert Milasan

L3 Support Engineer
SUSE Linux (http://www.suse.com)
email: rmila...@suse.com
GPG fingerprint: B6FE F4A8 0FA3 3040 3402  6FE7 2F64 167C 1909 6D1A


signature.asc
Description: PGP signature
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


Re: [systemd-devel] udevadm settle takes too long to finish

2013-12-09 Thread Thomas Bächler
Am 07.12.2013 22:29, schrieb Robert Milasan:
> From systemd-analyze dump:
> 
> Wants: systemd-udevd.service
> WantedBy: lvm2-activation-early.service
> WantedBy: lvm2-activation.service
> Before: lvm2-activation-early.service
> Before: sysinit.target
> After: systemd-udev-trigger.service
> After: systemd-journald.socket
> References: systemd-udevd.service
> References: systemd-udev-trigger.service
> References: sysinit.target
> References: systemd-journald.socket
> ReferencedBy: lvm2-activation-early.service
> ReferencedBy: lvm2-activation.service

What's the distribution you are using? Using udevadm settle for lvm is a
waste of boot time and isn't even guaranteed to work (ask Lennart, Kay
or Greg K-H for the full speech). It's a hackish workaround for LVM's
inability to activate volumes automatically.

Instead, a socket-activated lvmetad service should be used in
combination with the correct udev rules. The service files are provided
by LVM, but they reference weird redhat-specific units and from what I
saw have too many orderings, which results in slowing everything down
needlessly.

Currently, I use 69-dm-lvm-metad.rules provided by LVM in combination
with the unit files [1] and [2] (derived from the redhat units included
in LVM). This is fast and works great for me, although lvmetad has some
annoying bugs which have been reported to me, but which I could never
reproduce.

There is no way to make udevadm settle "faster" and the only solution is
(as Kay said already) is not using it.

[1]
https://projects.archlinux.org/svntogit/packages.git/tree/trunk/lvmetad.service?h=packages/lvm2
[2]
https://projects.archlinux.org/svntogit/packages.git/tree/trunk/lvmetad.socket?h=packages/lvm2



signature.asc
Description: OpenPGP digital signature
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel