diff options
author | KUMAAN <9maaan@gmail.com> | 2011-08-23 14:51:22 +0900 |
---|---|---|
committer | maximilian attems <max@stro.at> | 2012-05-19 00:45:33 +0200 |
commit | b01feb697800476d5a53c58ab31893a0653d9c95 (patch) | |
tree | 4b6f8287d1cf4c30a1c6edf667a9f0dcf386edaa | |
parent | 8c239c1b5144f7ded9fd9737b0d1c64ce1777a30 (diff) | |
download | klibc-b01feb697800476d5a53c58ab31893a0653d9c95.tar.gz |
[klibc] ipconfig: Write $PROTO as configuration protocol
This patch writes $PROTO as what protocol ipconfig used to configure
$DEVICE to /tmp/net-$DEVICE.conf file.
For example, $PROTO is either 'boop', 'dhcp', or 'none'.
Later, other scripts which source the file can known the protocol clearly.
Signed-off-by: KUMAAN <9maaan@gmail.com>
Acked-by: H. Peter Anvin <hpa@linux.intel.com>
Signed-off-by: maximilian attems <max@stro.at>
-rw-r--r-- | usr/kinit/ipconfig/main.c | 31 | ||||
-rw-r--r-- | usr/kinit/ipconfig/netdev.h | 1 |
2 files changed, 28 insertions, 4 deletions
diff --git a/usr/kinit/ipconfig/main.c b/usr/kinit/ipconfig/main.c index 3832921c47c4f..148ccb66fa3b1 100644 --- a/usr/kinit/ipconfig/main.c +++ b/usr/kinit/ipconfig/main.c @@ -45,6 +45,20 @@ struct state { struct state *next; }; +/* #define PROTO_x : for uint8_t proto of struct netdev */ +struct protoinfo { + char *name; +} protoinfos[] = { +#define PROTO_NONE 0 + {"none"}, +#define PROTO_BOOTP 1 + {"bootp"}, +#define PROTO_DHCP 2 + {"dhcp"}, +#define PROTO_RARP 3 + {"rarp"} +}; + static inline const char *my_inet_ntoa(uint32_t addr) { struct in_addr a; @@ -56,9 +70,13 @@ static inline const char *my_inet_ntoa(uint32_t addr) static void print_device_config(struct netdev *dev) { - printf("IP-Config: %s complete (from %s):\n", dev->name, - my_inet_ntoa(dev->serverid ? dev->serverid : dev->ip_server)); - printf(" address: %-16s ", my_inet_ntoa(dev->ip_addr)); + printf("IP-Config: %s complete", dev->name); + if (dev->proto == PROTO_BOOTP || dev->proto == PROTO_DHCP) + printf(" (%s from %s)", protoinfos[dev->proto].name, + my_inet_ntoa(dev->serverid ? + dev->serverid : dev->ip_server)); + + printf(":\n address: %-16s ", my_inet_ntoa(dev->ip_addr)); printf("broadcast: %-16s ", my_inet_ntoa(dev->ip_broadcast)); printf("netmask: %-16s\n", my_inet_ntoa(dev->ip_netmask)); printf(" gateway: %-16s ", my_inet_ntoa(dev->ip_gateway)); @@ -134,6 +152,7 @@ static void dump_device_config(struct netdev *dev) f = fopen(fn, "w"); if (f) { write_option(f, "DEVICE", dev->name); + write_option(f, "PROTO", protoinfos[dev->proto].name); write_option(f, "IPV4ADDR", my_inet_ntoa(dev->ip_addr)); write_option(f, "IPV4BROADCAST", @@ -231,6 +250,7 @@ static int process_receive_event(struct state *s, time_t now) break; case 1: s->state = DEVST_COMPLETE; + s->dev->proto = PROTO_BOOTP; dprintf("\n bootp reply\n"); break; } @@ -263,6 +283,7 @@ static int process_receive_event(struct state *s, time_t now) break; case DHCPACK: /* ACK received */ s->state = DEVST_COMPLETE; + s->dev->proto = PROTO_DHCP; break; case DHCPNAK: /* NAK received */ s->state = DEVST_DHCPDISC; @@ -598,8 +619,10 @@ static void bringup_device(struct netdev *dev) if (netdev_up(dev) == 0) { if (dev->caps) add_one_dev(dev); - else + else { + dev->proto = PROTO_NONE; complete_device(dev); + } } } diff --git a/usr/kinit/ipconfig/netdev.h b/usr/kinit/ipconfig/netdev.h index d1903dcd6e59b..f4198804e60cc 100644 --- a/usr/kinit/ipconfig/netdev.h +++ b/usr/kinit/ipconfig/netdev.h @@ -28,6 +28,7 @@ struct netdev { int fd; } rarp; + uint8_t proto; /* a protocol used (e.g. PROTO_DHCP) */ uint32_t ip_addr; /* my address */ uint32_t ip_broadcast; /* broadcast address */ uint32_t ip_server; /* server address */ |