[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>
diff --git a/usr/kinit/ipconfig/main.c b/usr/kinit/ipconfig/main.c
index 3832921..148ccb6 100644
--- a/usr/kinit/ipconfig/main.c
+++ b/usr/kinit/ipconfig/main.c
@@ -45,6 +45,20 @@
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 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 @@
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 @@
break;
case 1:
s->state = DEVST_COMPLETE;
+ s->dev->proto = PROTO_BOOTP;
dprintf("\n bootp reply\n");
break;
}
@@ -263,6 +283,7 @@
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 @@
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 d1903dc..f419880 100644
--- a/usr/kinit/ipconfig/netdev.h
+++ b/usr/kinit/ipconfig/netdev.h
@@ -28,6 +28,7 @@
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 */