[klibc] [patch] ipconfig fixes + run-init nit

maximilian attems max at stro.at
Wed Aug 25 11:59:40 PDT 2010


hello,

Preparing my first klibc maintainenace release. :)
My plan is to have the patches cook in klibc-queue and once 
everythings is fine deploy them in the main klibc repo.
Please test/review belows patches.

I plan to release the current queue really soon for klibc 1.5.20
due to the urgent ipconfig fixes. For now you find my patch queue on:
http://git.kernel.org/?p=libs/klibc/klibc-queue.git;a=summary

beware that this patch-queue might rebase from time to time in the future.
The current diff and shortlog show the ipconfig centric fixes.


Erwan Velu (1):
      [klibc] ipconfig: non zero exit on timeout

H. Peter Anvin (1):
      [klibc] 1.5.19 released, next version is 1.5.20

Julien BLACHE (2):
      [klibc] ipconfig: fix infinite loop
      [klibc] ipconfig: differentiate between error and non-DHCP/BOOTP traffic in packet_recv()

Michael Prokop (1):
      [klibc] ipconfig fix dns domain

maximilian attems (1):
      [klibc] run-init: get rid of over paranoid test for /init


git diff -M --stat --summary klibc-1.5.19..
 usr/kinit/ipconfig/bootp_proto.c |    2 +-
 usr/kinit/ipconfig/dhcp_proto.c  |    4 ++--
 usr/kinit/ipconfig/main.c        |   16 ++++++++++------
 usr/kinit/ipconfig/packet.c      |    5 +++--
 usr/kinit/run-init/runinitlib.c  |    4 ----
 usr/klibc/version                |    2 +-
 6 files changed, 17 insertions(+), 16 deletions(-)

thanks to all the involved parties.
maks

commit 61368211ae1e77fa2ef82bb9135c7b8e9447023e
Author: maximilian attems <max at stro.at>
Date:   Wed Aug 25 20:34:26 2010 +0200

    [klibc] run-init: get rid of over paranoid test for /init
    
    switch_root in util-linux hasn't it either.
    
    cc0c0262 added the checks, but probably didn't have the following
    application in mind.
    
    In fact it can break chainloading of bigger initramfs out of small one:
    "I boot via pxe, kernel + very small ramfs this ramfs start an
    application that grabs a bigger ramfs and store it locally
    I did the following: creating a tmpfs, uncpio the ramfs and try to
    run-init on it, but my miniramfs doesn't have a /init as I specified
    rdinit=/sbin/init."
    
    So for now just get rid of that check.
    
    Reported-by: Erwan Velu <erwan.velu at zodiacaerospace.com>
    Signed-off-by: maximilian attems <max at stro.at>

diff --git a/usr/kinit/run-init/runinitlib.c b/usr/kinit/run-init/runinitlib.c
index 423637e..50baa3d 100644
--- a/usr/kinit/run-init/runinitlib.c
+++ b/usr/kinit/run-init/runinitlib.c
@@ -176,10 +176,6 @@ const char *run_init(const char *realroot, const char *console,
 	if (rst.st_dev == cst.st_dev)
 		return "current directory on the same filesystem as the root";
 
-	/* The initramfs should have /init */
-	if (stat("/init", &ist) || !S_ISREG(ist.st_mode))
-		return "can't find /init on initramfs";
-
 	/* Make sure we're on a ramfs */
 	if (statfs("/", &sfs))
 		return "statfs /";

commit 2028152b7af7700e01bd3300c3f7d903afbf34de
Author: Erwan Velu <erwan.velu at zodiacaerospace.com>
Date:   Tue Aug 24 10:00:23 2010 +0200

    [klibc] ipconfig: non zero exit on timeout
    
    I was scripting in klibc and wanted to make an action when the dhcp client
    failed at grabing an IP after the defined timeout.
    I found that klibc always exit 0 which isn't that convenient .
    
    Belows patch fixes the issue.
    
    [ small coding style changes - maks]
    Signed-off-by: maximilian attems <max at stro.at>

diff --git a/usr/kinit/ipconfig/main.c b/usr/kinit/ipconfig/main.c
index b014128..b392e6a 100644
--- a/usr/kinit/ipconfig/main.c
+++ b/usr/kinit/ipconfig/main.c
@@ -331,7 +331,7 @@ static int loop(void)
 	struct pollfd fds[NR_FDS];
 	struct state *s;
 	int pkt_fd;
-	int nr = 0;
+	int nr = 0, rc = 0;
 	struct timeval now, prev;
 	time_t start;
 
@@ -396,6 +396,7 @@ static int loop(void)
 			    now.tv_sec - start >= loop_timeout) {
 				printf("IP-Config: no response after %d "
 				       "secs - giving up\n", loop_timeout);
+				rc = -1;
 				goto bail;
 			}
 
@@ -410,7 +411,7 @@ static int loop(void)
       bail:
 	packet_close();
 
-	return 0;
+	return rc;
 }
 
 static int add_one_dev(struct netdev *dev)
@@ -724,7 +725,7 @@ int ipconfig_main(int argc, char *argv[])
 {
 	struct netdev *dev;
 	int c, port;
-	int err;
+	int err = 0;
 
 	/* If progname is set we're invoked from another program */
 	if (!progname) {
@@ -802,8 +803,8 @@ int ipconfig_main(int argc, char *argv[])
 			       "dest to %d\n",
 			       cfg_local_port, cfg_remote_port);
 		}
-		loop();
+		err = loop();
 	}
 
-	return 0;
+	return err;
 }

commit 8a9b80da8295a8b21a4de44840a36aab72654a5b
Author: Michael Prokop <mika at debian.org>
Date:   Tue Aug 24 18:04:40 2010 +0200

    [klibc] ipconfig fix dns domain
    
    I'm trying to boot a KVM over the net with a FAI created nfsroot. The
    boot procedure fails with an error message that instructs me to file this bug.
    
    In /live.log I see the following error message:
    
    /init: /tmp/net-eth0.conf: line 9: int-domain2.priv: not found
    
    http://bugs.debian.org/594208
    Belows trivial patch addresses this issue.
    
    Signed-off-by: Michael Prokop <mika at debian.org>
    Tested-by: Reinhard Tartler <siretart at tauware.de>
    Signed-off-by: maximilian attems <max at stro.at>

diff --git a/usr/kinit/ipconfig/main.c b/usr/kinit/ipconfig/main.c
index f00041b..b014128 100644
--- a/usr/kinit/ipconfig/main.c
+++ b/usr/kinit/ipconfig/main.c
@@ -115,7 +115,7 @@ static void dump_device_config(struct netdev *dev)
 		fprintf(f, "IPV4DNS1=%s\n",
 			my_inet_ntoa(dev->ip_nameserver[1]));
 		fprintf(f, "HOSTNAME=%s\n", dev->hostname);
-		fprintf(f, "DNSDOMAIN=%s\n", dev->dnsdomainname);
+		fprintf(f, "DNSDOMAIN=\"%s\"\n", dev->dnsdomainname);
 		fprintf(f, "NISDOMAIN=%s\n", dev->nisdomainname);
 		fprintf(f, "ROOTSERVER=%s\n", my_inet_ntoa(dev->ip_server));
 		fprintf(f, "ROOTPATH=%s\n", dev->bootpath);

commit b02b0f71aa7be125f0d64e44124d7f7ead0175b5
Author: Julien BLACHE <julien-externe.blache at edf.fr>
Date:   Tue Aug 10 15:37:10 2010 +0200

    [klibc] ipconfig: differentiate between error and non-DHCP/BOOTP traffic in packet_recv()
    
    Commit 4efbcf90f60e27febe883ef052454d8cfded5c15 badly broke ipconfig by
    turning packet_recv() into an all-or-nothing function. Before this commit,
    packet_recv() did distinguish between a DHCP/BOOTP packet that's of interest,
    random UDP packets we don't care about and errors.
    
    After the patch, either a packet is a DHCP/BOOTP packet or packet_recv() exits
    with an error.
    
    This breaks ipconfig on big, noisy LANs where random UDP traffic can arrive
    before the DHCP reply and throw the device into DEVST_ERROR state.
    
    This fixes http://bugs.debian.org/552554
    
    Tested-by: Michael Prokop <mika at debian.org>
    Signed-off-by: maximilian attems <max at stro.at>

diff --git a/usr/kinit/ipconfig/bootp_proto.c b/usr/kinit/ipconfig/bootp_proto.c
index 42dfad3..baf9d3e 100644
--- a/usr/kinit/ipconfig/bootp_proto.c
+++ b/usr/kinit/ipconfig/bootp_proto.c
@@ -171,7 +171,7 @@ int bootp_recv_reply(struct netdev *dev)
 
 	ret = packet_recv(iov, 3);
 	if (ret <= 0)
-		return -1;
+		return ret;
 
 	if (ret < sizeof(struct bootp_hdr) ||
 	    bootp.op != BOOTP_REPLY ||	/* RFC951 7.5 */
diff --git a/usr/kinit/ipconfig/dhcp_proto.c b/usr/kinit/ipconfig/dhcp_proto.c
index 2a2651a..fc0494d 100644
--- a/usr/kinit/ipconfig/dhcp_proto.c
+++ b/usr/kinit/ipconfig/dhcp_proto.c
@@ -148,8 +148,8 @@ static int dhcp_recv(struct netdev *dev)
 	int ret;
 
 	ret = packet_recv(iov, 3);
-	if (ret == 0)
-		return -1;
+	if (ret <= 0)
+		return ret;
 
 	dprintf("\n   dhcp xid %08x ", dev->bootp.xid);
 
diff --git a/usr/kinit/ipconfig/packet.c b/usr/kinit/ipconfig/packet.c
index d242457..84267b7 100644
--- a/usr/kinit/ipconfig/packet.c
+++ b/usr/kinit/ipconfig/packet.c
@@ -215,7 +215,8 @@ void packet_discard(void)
  * Receive a bootp packet.  The options are listed in iov[1...iov_len].
  * iov[0] must point to the bootp packet header.
  * Returns:
- *  0 = Error, try again later
+ * -1 = Error, try again later
+*   0 = Discarded packet (non-DHCP/BOOTP traffic)
  * >0 = Size of packet
  */
 int packet_recv(struct iovec *iov, int iov_len)
@@ -236,7 +237,7 @@ int packet_recv(struct iovec *iov, int iov_len)
 	ret = recvfrom(pkt_fd, &iph, sizeof(struct iphdr),
 		       MSG_PEEK, NULL, NULL);
 	if (ret == -1)
-		return 0;
+		return -1;
 
 	if (iph.ihl < 5 || iph.version != IPVERSION)
 		goto discard_pkt;

commit 47da4f6ab856250854465f88edc6d76ca0ba017b
Author: Julien BLACHE <julien-externe.blache at edf.fr>
Date:   Tue Aug 10 13:57:41 2010 +0200

    [klibc] ipconfig: fix infinite loop
    
    The first switch() statement in process_receive_event() did not
    handle the DEVST_ERROR state, causing the timeout to be endlessly
    increased by 10 seconds at each iteration in the second switch()
    statement.
    
    The second switch() statement is only here to catch state changes
    caused by the first one, so DEVST_ERROR must be caught by the first
    one to ignore the device until the timeout expires.
    
    Tested-by: Michael Prokop <mika at debian.org>
    Signed-off-by: maximilian attems <max at stro.at>

diff --git a/usr/kinit/ipconfig/main.c b/usr/kinit/ipconfig/main.c
index d46aa5e..f00041b 100644
--- a/usr/kinit/ipconfig/main.c
+++ b/usr/kinit/ipconfig/main.c
@@ -179,6 +179,9 @@ static int process_receive_event(struct state *s, time_t now)
 	int handled = 1;
 
 	switch (s->state) {
+	case DEVST_ERROR:
+		return 0; /* Not handled */
+
 	case DEVST_BOOTP:
 		s->restart_state = DEVST_BOOTP;
 		switch (bootp_recv_reply(s->dev)) {

commit 73f0df27a6c8776510eba1d89da99ee6f6814527
Author: H. Peter Anvin <hpa at zytor.com>
Date:   Tue Aug 10 16:40:22 2010 +0000

    [klibc] 1.5.19 released, next version is 1.5.20

diff --git a/usr/klibc/version b/usr/klibc/version
index e7a15ce..a7ccabd 100644
--- a/usr/klibc/version
+++ b/usr/klibc/version
@@ -1 +1 @@
-1.5.19
+1.5.20



More information about the klibc mailing list