Deleted Added
full compact
net.c (256281) net.c (283510)
1/*-
2 * Copyright (c) 2000-2001 Benno Rice
3 * Copyright (c) 2007 Semihalf, Rafal Jaworowski <raj@semihalf.com>
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

--- 12 unchanged lines hidden (view full) ---

21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 */
27
28#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2000-2001 Benno Rice
3 * Copyright (c) 2007 Semihalf, Rafal Jaworowski <raj@semihalf.com>
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

--- 12 unchanged lines hidden (view full) ---

21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 */
27
28#include <sys/cdefs.h>
29__FBSDID("$FreeBSD: stable/10/sys/boot/uboot/lib/net.c 193111 2009-05-30 19:28:38Z marcel $");
29__FBSDID("$FreeBSD: stable/10/sys/boot/uboot/lib/net.c 283510 2015-05-25 01:29:45Z ian $");
30
31#include <sys/param.h>
32#include <sys/types.h>
33#include <sys/socket.h>
34
35#include <net/if.h>
36#include <netinet/in.h>
37#include <netinet/in_systm.h>
38#include <netinet/if_ether.h>
39#include <netinet/ip.h>
40
41#include <stand.h>
42#include <net.h>
43#include <netif.h>
44
45#include "api_public.h"
46#include "glue.h"
47#include "libuboot.h"
30
31#include <sys/param.h>
32#include <sys/types.h>
33#include <sys/socket.h>
34
35#include <net/if.h>
36#include <netinet/in.h>
37#include <netinet/in_systm.h>
38#include <netinet/if_ether.h>
39#include <netinet/ip.h>
40
41#include <stand.h>
42#include <net.h>
43#include <netif.h>
44
45#include "api_public.h"
46#include "glue.h"
47#include "libuboot.h"
48#include "dev_net.h"
48
49static int net_probe(struct netif *, void *);
50static int net_match(struct netif *, void *);
51static void net_init(struct iodesc *, void *);
52static int net_get(struct iodesc *, void *, size_t, time_t);
53static int net_put(struct iodesc *, void *, size_t);
54static void net_end(struct netif *);
55

--- 23 unchanged lines hidden (view full) ---

79 uint8_t sc_rxbuf[ETHER_MAX_LEN];
80 uint8_t sc_txbuf[ETHER_MAX_LEN + PKTALIGN];
81 uint8_t *sc_txbufp;
82 int sc_handle; /* device handle for ub_dev_xxx */
83};
84
85static struct uboot_softc uboot_softc;
86
49
50static int net_probe(struct netif *, void *);
51static int net_match(struct netif *, void *);
52static void net_init(struct iodesc *, void *);
53static int net_get(struct iodesc *, void *, size_t, time_t);
54static int net_put(struct iodesc *, void *, size_t);
55static void net_end(struct netif *);
56

--- 23 unchanged lines hidden (view full) ---

80 uint8_t sc_rxbuf[ETHER_MAX_LEN];
81 uint8_t sc_txbuf[ETHER_MAX_LEN + PKTALIGN];
82 uint8_t *sc_txbufp;
83 int sc_handle; /* device handle for ub_dev_xxx */
84};
85
86static struct uboot_softc uboot_softc;
87
88/*
89 * get_env_net_params()
90 *
91 * Attempt to obtain all the parms we need for netbooting from the U-Boot
92 * environment. If we fail to obtain the values it may still be possible to
93 * netboot; the net_dev code will attempt to get the values from bootp, rarp,
94 * and other such sources.
95 *
96 * If rootip.s_addr is non-zero net_dev assumes the required global variables
97 * are set and skips the bootp inquiry. For that reason, we don't set rootip
98 * until we've verified that we have at least the minimum required info.
99 *
100 * This is called from netif_init() which can result in it getting called
101 * multiple times, by design. The network code at higher layers zeroes out
102 * rootip when it closes a network interface, so if it gets opened again we have
103 * to obtain all this info again.
104 */
105static void
106get_env_net_params()
107{
108 char *envstr;
109 in_addr_t rootaddr, serveraddr;
110
111 /* Silently get out right away if we don't have rootpath. */
112 if (ub_env_get("rootpath") == NULL)
113 return;
114
115 /*
116 * Our own IP address must be valid. Silently get out if it's not set,
117 * but whine if it's there and we can't parse it.
118 */
119 if ((envstr = ub_env_get("ipaddr")) == NULL)
120 return;
121 if ((myip.s_addr = inet_addr(envstr)) == INADDR_NONE) {
122 printf("Could not parse ipaddr '%s'\n", envstr);
123 return;
124 }
125
126 /*
127 * Netmask is optional, default to the "natural" netmask for our IP, but
128 * whine if it was provided and we couldn't parse it.
129 */
130 if ((envstr = ub_env_get("netmask")) != NULL &&
131 (netmask = inet_addr(envstr)) == INADDR_NONE) {
132 printf("Could not parse netmask '%s'\n", envstr);
133 }
134 if (netmask == INADDR_NONE) {
135 if (IN_CLASSA(myip.s_addr))
136 netmask = IN_CLASSA_NET;
137 else if (IN_CLASSB(myip.s_addr))
138 netmask = IN_CLASSB_NET;
139 else
140 netmask = IN_CLASSC_NET;
141 }
142
143 /*
144 * Get optional serverip before rootpath; the latter can override it.
145 * Whine only if it's present but can't be parsed.
146 */
147 serveraddr = INADDR_NONE;
148 if ((envstr = ub_env_get("serverip")) != NULL) {
149 if ((serveraddr = inet_addr(envstr)) == INADDR_NONE)
150 printf("Could not parse serverip '%s'\n", envstr);
151 }
152
153 /*
154 * There must be a rootpath. It may be ip:/path or it may be just the
155 * path in which case the ip needs to be in serverip.
156 */
157 if ((envstr = ub_env_get("rootpath")) == NULL)
158 return;
159 strncpy(rootpath, envstr, sizeof(rootpath) - 1);
160 rootaddr = net_parse_rootpath();
161 if (rootaddr == INADDR_NONE)
162 rootaddr = serveraddr;
163 if (rootaddr == INADDR_NONE) {
164 printf("No server address for rootpath '%s'\n", envstr);
165 return;
166 }
167 rootip.s_addr = rootaddr;
168
169 /*
170 * Gateway IP is optional unless rootip is on a different net in which
171 * case whine if it's missing or we can't parse it, and set rootip addr
172 * to zero, which signals to other network code that network params
173 * aren't set (so it will try dhcp, bootp, etc).
174 */
175 envstr = ub_env_get("gatewayip");
176 if (!SAMENET(myip, rootip, netmask)) {
177 if (envstr == NULL) {
178 printf("Need gatewayip for a root server on a "
179 "different network.\n");
180 rootip.s_addr = 0;
181 return;
182 }
183 if ((gateip.s_addr = inet_addr(envstr) == INADDR_NONE)) {
184 printf("Could not parse gatewayip '%s'\n", envstr);
185 rootip.s_addr = 0;
186 return;
187 }
188 }
189}
190
87static int
88net_match(struct netif *nif, void *machdep_hint)
89{
90 char **a = (char **)machdep_hint;
91
92 if (memcmp("net", *a, 3) == 0)
93 return (1);
94

--- 122 unchanged lines hidden (view full) ---

217 /* Get MAC address */
218 di = ub_dev_get(sc->sc_handle);
219 memcpy(desc->myea, di->di_net.hwaddr, 6);
220 if (memcmp (desc->myea, "\0\0\0\0\0\0", 6) == 0) {
221 panic("%s%d: empty ethernet address!",
222 nif->nif_driver->netif_bname, nif->nif_unit);
223 }
224
191static int
192net_match(struct netif *nif, void *machdep_hint)
193{
194 char **a = (char **)machdep_hint;
195
196 if (memcmp("net", *a, 3) == 0)
197 return (1);
198

--- 122 unchanged lines hidden (view full) ---

321 /* Get MAC address */
322 di = ub_dev_get(sc->sc_handle);
323 memcpy(desc->myea, di->di_net.hwaddr, 6);
324 if (memcmp (desc->myea, "\0\0\0\0\0\0", 6) == 0) {
325 panic("%s%d: empty ethernet address!",
326 nif->nif_driver->netif_bname, nif->nif_unit);
327 }
328
329 /* Attempt to get netboot params from the u-boot env. */
330 get_env_net_params();
331 if (myip.s_addr != 0)
332 desc->myip = myip;
333
225#if defined(NETIF_DEBUG)
226 printf("network: %s%d attached to %s\n", nif->nif_driver->netif_bname,
227 nif->nif_unit, ether_sprintf(desc->myea));
228#endif
229
230 /* Set correct alignment for TX packets */
231 sc->sc_txbufp = sc->sc_txbuf;
232 if ((unsigned long)sc->sc_txbufp % PKTALIGN)

--- 14 unchanged lines hidden ---
334#if defined(NETIF_DEBUG)
335 printf("network: %s%d attached to %s\n", nif->nif_driver->netif_bname,
336 nif->nif_unit, ether_sprintf(desc->myea));
337#endif
338
339 /* Set correct alignment for TX packets */
340 sc->sc_txbufp = sc->sc_txbuf;
341 if ((unsigned long)sc->sc_txbufp % PKTALIGN)

--- 14 unchanged lines hidden ---