Skip to content

Commit b44cc1b

Browse files
committed
loader: do not try to open directories with TFTP
Attempting to mount or even open / with some tftp servers causes a several minute delay in boot. Since opening a directory via TFTP does not make sense, we avoid it. We don't know if using TFTP until after net_open() has been called. Add an is_tftp() accessor to avoid everyone having to include all the net* headers. Sponsored by: Juniper Networks, Inc. Differential Revision: https://reviews.freebsd.org/D51447
1 parent aaf65a1 commit b44cc1b

File tree

4 files changed

+23
-2
lines changed

4 files changed

+23
-2
lines changed

stand/common/dev_net.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ net_open(struct open_file *f, ...)
182182
setenv("boot.netif.mtu", mtu, 1);
183183
}
184184

185+
DEBUG_PRINTF(1,("%s: netproto=%d\n", __func__, netproto));
185186
}
186187
netdev_opens++;
187188
dev->d_opendata = &netdev_sock;
@@ -193,7 +194,7 @@ net_close(struct open_file *f)
193194
{
194195
struct devdesc *dev;
195196

196-
DEBUG_PRINTF(1,("%s: opens=%d\n", __func__, netdev_opens));
197+
DEBUG_PRINTF(2,("%s: opens=%d\n", __func__, netdev_opens));
197198

198199
dev = f->f_devdata;
199200
dev->d_opendata = NULL;
@@ -344,6 +345,12 @@ net_print(int verbose)
344345
return (ret);
345346
}
346347

348+
bool
349+
is_tftp(void)
350+
{
351+
return (netproto == NET_TFTP);
352+
}
353+
347354
/*
348355
* Parses the rootpath if present
349356
*

stand/libsa/mount.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,10 @@ mount(const char *dev, const char *path, int flags __unused, void *data)
107107
fs = file_system[i];
108108
if (fs->fo_mount == NULL)
109109
continue;
110-
110+
DEBUG_PRINTF(1,("%s: fs=%s path=%s\n",
111+
__func__, fs->fs_name, path));
112+
if (is_tftp())
113+
break;
111114
if (fs->fo_mount(dev, path, &data) != 0)
112115
continue;
113116

stand/libsa/open.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ open(const char *fname, int mode)
138138
struct fs_ops *fs;
139139
struct open_file *f;
140140
int fd, i, error, besterror;
141+
bool is_dir;
142+
size_t n;
141143
const char *file;
142144

143145
TSENTER();
@@ -182,8 +184,14 @@ open(const char *fname, int mode)
182184

183185
/* pass file name to the different filesystem open routines */
184186
besterror = ENOENT;
187+
n = strlen(file);
188+
is_dir = (n > 0 && file[n - 1] == '/');
185189
for (i = 0; file_system[i] != NULL; i++) {
186190
fs = file_system[i];
191+
if (is_dir && is_tftp()) {
192+
error = EOPNOTSUPP;
193+
goto err;
194+
}
187195
error = (fs->fo_open)(file, f);
188196
if (error == 0)
189197
goto ok;

stand/libsa/stand.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,9 @@ extern void *reallocf(void *, size_t);
507507
*/
508508
caddr_t ptov(uintptr_t);
509509

510+
/* dev_net.c */
511+
bool is_tftp(void);
512+
510513
/* features.c */
511514
typedef void (feature_iter_fn)(void *, const char *, const char *, bool);
512515

0 commit comments

Comments
 (0)