The Pedigree Project 0.1
modules/system/confignics/main.cc
1/*
2 * Copyright (c) 2008-2014, Pedigree Developers
3 *
4 * Please see the CONTRIB file in the root of the source tree for a full
5 * list of contributors.
6 *
7 * Permission to use, copy, modify, and distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
10 *
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 */
19
20#include "pedigree/kernel/Log.h"
21#include "pedigree/kernel/Service.h"
22#include "pedigree/kernel/ServiceManager.h"
23#include "pedigree/kernel/machine/DeviceHashTree.h"
24#include "pedigree/kernel/processor/Processor.h"
25
26#include "modules/Module.h"
30#include "modules/system/network-stack/NetworkStack.h"
31
32static int configureInterfaces() {
33 // Fill out the device hash table (needed in RoutingTable)
34 DeviceHashTree::instance().fill();
35
36 // Build routing tables - try to find a default configuration that can
37 // connect to the outside world
38 IpAddress empty;
39 Network* pDefaultCard = 0;
40 NetworkStack& networkStack = NetworkStack::instance();
41 for (size_t i = 0;; ++i) {
43 if (!networkStack.acquireDevice(i, device)) {
44 break;
45 }
46
48 struct netif* iface = device.interface();
49
50 // Do the initial setup we need to get the interface up.
51 ip4_addr_t ipaddr;
52 ip4_addr_t netmask;
53 ip4_addr_t gateway;
54 ByteSet(&ipaddr, 0, sizeof(ipaddr));
55 ByteSet(&netmask, 0, sizeof(netmask));
56 ByteSet(&gateway, 0, sizeof(gateway));
57
58 netif_set_addr(iface, &ipaddr, &netmask, &gateway);
59 netif_set_ip6_autoconfig_enabled(iface, 1);
60 netif_create_ip6_linklocal_address(iface, 1);
61 netif_set_link_up(iface);
62 netif_set_up(iface);
63
64 // Kick off DHCP for this interface.
66 dhcp_start(iface);
67 }
68
69 return 0;
70}
71
72static bool init() {
73 configureInterfaces();
74 return false; // unload after starting dhcp for all interfaces
75}
76
77static void destroy() {}
78
79MODULE_INFO("confignics", &init, &destroy, "network-stack", "lwip");
80MODULE_OPTIONAL_DEPENDS("nics", "pcap");
void fill(Device *root=0)
static NetworkStack & instance()
MUST_USE_RESULT bool acquireDevice(size_t n, DeviceLease &lease)
void netif_set_link_up(struct netif *netif)
Definition netif.c:754
void netif_set_up(struct netif *netif)
Definition netif.c:643
Definition netif.h:244