summaryrefslogtreecommitdiff
path: root/com32/libupload/upload_tftp.c
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@linux.intel.com>2016-04-06 12:16:21 -0700
committerH. Peter Anvin <hpa@linux.intel.com>2016-04-06 12:16:21 -0700
commitcfafd66933bfd9fd55c58d7f8fa9f468386ba385 (patch)
tree6d31d1303cb1221057fa5eaaf1e830cc8b88ef0d /com32/libupload/upload_tftp.c
parent9acbffd33b9200ffe37833463b4d4478e824295a (diff)
downloadsyslinux-cfafd66933bfd9fd55c58d7f8fa9f468386ba385.tar.gz
libupload: don't error out because the tftp functions are unavailable
Provide weak stubs for the case where the tftp functions aren't available. This prevents link failures for the case of running on top of non-network cores. Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
Diffstat (limited to 'com32/libupload/upload_tftp.c')
-rw-r--r--com32/libupload/upload_tftp.c78
1 files changed, 66 insertions, 12 deletions
diff --git a/com32/libupload/upload_tftp.c b/com32/libupload/upload_tftp.c
index 387113ba..80fe0bfb 100644
--- a/com32/libupload/upload_tftp.c
+++ b/com32/libupload/upload_tftp.c
@@ -10,23 +10,29 @@
#include <sys/times.h>
#include <fs/pxe/pxe.h>
#include <fs/pxe/url.h>
+#include <fs/pxe/tftp.h>
#include "upload_backend.h"
const char *tftp_string_error_message[]={
-"Unknown error",
-"File not found",
-"Access Denied",
-"Disk Full",
-"Illegal Operation",
-"Unknown Transfert ID",
-"File already exists",
-"Unknown User",
-"Negociation failed",
-"Unable to resolve hostname", // not in RFC
-"Unable to connect", // not in RFC
-"No Error",
+ "Unknown error",
+ "File not found",
+ "Access Denied",
+ "Disk Full",
+ "Illegal Operation",
+ "Unknown Transfer ID",
+ "File already exists",
+ "Unknown User",
+ "Negotiation failed",
+
+ /* These are not in any RFC, defined internally */
+ "Unable to resolve hostname",
+ "Unable to connect",
+ "No Error",
+ "Network unavailable",
};
+static bool have_real_network(void);
+
static int upload_tftp_write(struct upload_backend *be) {
const union syslinux_derivative_info *sdi =
syslinux_derivative_info();
@@ -36,6 +42,11 @@ static int upload_tftp_write(struct upload_backend *be) {
uint32_t ip;
int err;
+ if (!have_real_network()) {
+ dprintf("\nNot running from the network\n");
+ return -TFTP_ERR_NO_NETWORK;
+ }
+
if (be->argv[1]) {
ip = pxe_dns(be->argv[1]);
if (!ip) {
@@ -75,3 +86,46 @@ struct upload_backend upload_tftp = {
.minargs = 1,
.write = upload_tftp_write,
};
+
+/*
+ * Dummy functions to prevent link failure for non-network cores
+ */
+static int _dummy_tftp_put(struct url_info *url, int flags,
+ struct inode *inode, const char **redir,
+ char *data, int data_length)
+{
+ (void)url;
+ (void)flags;
+ (void)inode;
+ (void)redir;
+ (void)data;
+ (void)data_length;
+
+ return -TFTP_ERR_NO_NETWORK;
+}
+
+__weak int __attribute__((alias("_dummy_tftp_put")))
+tftp_put(struct url_info *url, int flags, struct inode *inode,
+ const char **redir, char *data, int data_length);
+
+static int _dummy_tftp_put(struct url_info *url, int flags,
+ struct inode *inode, const char **redir,
+ char *data, int data_length);
+
+static bool have_real_network(void)
+{
+ return tftp_put != _dummy_tftp_put;
+}
+
+__weak uint32_t dns_resolv(const char *host)
+{
+ (void)host;
+
+ return 0;
+}
+
+__weak void parse_url(struct url_info *ui, char *url)
+{
+ (void)ui;
+ (void)url;
+}