Fixed ipv6 default address; tunnel broker is by default turned off
[ZeXOS.git] / kernel / core / net / if.c
blob792a8e53406bac6a9598c5a44fc613ddede5b944
1 /*
2 * ZeX/OS
3 * Copyright (C) 2008 Tomas 'ZeXx86' Jedrzejek (zexx86@gmail.com)
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include <system.h>
21 #include <string.h>
22 #include <net/eth.h>
23 #include <net/net.h>
24 #include <net/if.h>
25 #include <net/ip.h>
26 #include <net/tun.h>
28 netif_t netif_list;
30 #define DEFAULT_IP_ADDRESS NET_IPV4_TO_ADDR (192,168,1,50)
31 #define DEFAULT_GW_ADDRESS NET_IPV4_TO_ADDR (192,168,1,1)
33 netif_t *netif_findbyname (char *name)
35 netif_t *netif;
36 for (netif = netif_list.next; netif != &netif_list; netif = netif->next) {
37 if (!strcmp (netif->dev->name, name))
38 return netif;
41 return 0;
44 unsigned netif_ip_addr (netif_t *netif, net_ipv4 ip)
46 if (!netif)
47 return 0;
49 netif->ip = ip;
51 return 1;
54 unsigned netif_ipv6_addr (netif_t *netif, net_ipv6 ip)
56 if (!netif)
57 return 0;
59 memcpy (netif->ipv6, ip, sizeof (net_ipv6));
61 return 1;
64 unsigned netif_gw_addr (netif_t *netif, net_ipv4 gw)
66 if (!netif)
67 return 0;
69 netif->gw = gw;
71 return 1;
74 netif_t *netif_create (struct netdev_t *dev)
76 if (!dev)
77 return 0;
79 netif_t *netif;
81 /* alloc and init context */
82 netif = (netif_t *) kmalloc (sizeof (netif_t));
84 if (!netif)
85 return 0;
87 /* init 6 bytes for MAC address */
88 netif->addr = (struct netaddr_t *) kmalloc (sizeof (struct netaddr_t));
90 if (!netif->addr)
91 return 0;
93 netif->dev = dev;
95 if (!dev->dev_addr)
96 return 0;
98 netif_ip_addr (netif, DEFAULT_IP_ADDRESS);
99 netif_gw_addr (netif, DEFAULT_GW_ADDRESS);
101 net_ipv6 ipv6;
102 NET_IPV6_TO_ADDR (ipv6, 0xfc00, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x10);
103 //NET_IPV6_TO_ADDR (ipv6, 0x2002, 0x470, 0x1f0a, 0x4d3, 0x0, 0x0, 0x0, 0x1);
105 netif_ipv6_addr (netif, ipv6);
107 /* add into list */
108 netif->next = &netif_list;
109 netif->prev = netif_list.prev;
110 netif->prev->next = netif;
111 netif->next->prev = netif;
113 return netif;
116 void iflist_display ()
118 netif_t *netif;
119 for (netif = netif_list.next; netif != &netif_list; netif = netif->next) {
120 if (!netif)
121 continue;
123 printf ("if: %s - MAC addr: %02x:%02x:%02x:%02x:%02x:%02x\n\tRx bytes: %lu\tTx bytes: %lu\n", netif->dev->name,
124 netif->dev->dev_addr[0], netif->dev->dev_addr[1], netif->dev->dev_addr[2],
125 netif->dev->dev_addr[3], netif->dev->dev_addr[4], netif->dev->dev_addr[5],
126 netif->dev->info_rx, netif->dev->info_tx);
127 printf ("\tEthernet IP address:\t"); net_proto_ip_print (netif->ip);
128 printf ("\n\t\t\t\t"); net_proto_ipv6_print (netif->ipv6);
129 printf ("\n\tGateway IP address:\t"); net_proto_ip_print (netif->gw);
131 if (tun6_addr_get ()) {
132 printf ("\n\tTunnel IP address:\t::"); net_proto_ip_print (tun6_addr_get ());
135 printf ("\n");
139 unsigned netif_read (struct netdev_t *dev, char *buf)
142 return 1;
145 unsigned init_netif ()
147 netif_list.next = &netif_list;
148 netif_list.prev = &netif_list;
150 if (!init_proto_arp ())
151 return 0;
153 if (!init_proto_ndp ())
154 return 0;
156 return 1;