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 "modules/Module.h"
21 #include "modules/system/network-stack/NetworkStack.h"
22 #include "pedigree/kernel/Log.h"
23 #include "pedigree/kernel/Service.h"
24 #include "pedigree/kernel/ServiceManager.h"
25 #include "pedigree/kernel/machine/DeviceHashTree.h"
26 #include "pedigree/kernel/processor/Processor.h"
27 
31 
32 static int configureInterfaces()
33 {
34  // Fill out the device hash table (needed in RoutingTable)
35  DeviceHashTree::instance().fill();
36 
37  // Build routing tables - try to find a default configuration that can
38  // connect to the outside world
39  IpAddress empty;
40  Network *pDefaultCard = 0;
41  for (size_t i = 0; i < NetworkStack::instance().getNumDevices(); i++)
42  {
45 
46  struct netif *iface = NetworkStack::instance().getInterface(card);
47  if (!iface)
48  {
49  continue;
50  }
51 
52  // Do the initial setup we need to get the interface up.
53  ip4_addr_t ipaddr;
54  ip4_addr_t netmask;
55  ip4_addr_t gateway;
56  ByteSet(&ipaddr, 0, sizeof(ipaddr));
57  ByteSet(&netmask, 0, sizeof(netmask));
58  ByteSet(&gateway, 0, sizeof(gateway));
59 
60  netif_set_addr(iface, &ipaddr, &netmask, &gateway);
61  netif_set_ip6_autoconfig_enabled(iface, 1);
62  netif_create_ip6_linklocal_address(iface, 1);
63  netif_set_link_up(iface);
64  netif_set_up(iface);
65  }
66 
67  return 0;
68 }
69 
70 static bool init()
71 {
72  configureInterfaces();
73  return false; // unload after starting dhcp for all interfaces
74 }
75 
76 static void destroy()
77 {
78 }
79 
80 MODULE_INFO("confignics", &init, &destroy, "network-stack", "lwip");
81 MODULE_OPTIONAL_DEPENDS("nics", "pcap");
Network * getDevice(size_t n)
Definition: netif.h:244
void netif_set_up(struct netif *netif)
Definition: netif.c:643
static NetworkStack & instance()
Definition: NetworkStack.h:47
size_t getNumDevices()
void fill(Device *root=0)
void netif_set_link_up(struct netif *netif)
Definition: netif.c:754
struct netif * getInterface(Network *pCard) const
Definition: NetworkStack.h:126