aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFam Zheng <famz@redhat.com>2018-09-14 15:26:16 +0800
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2018-10-21 21:24:55 +0200
commitb6477f7746aadea908e1007c82bac7de44905bd6 (patch)
tree6965727f6c111a0600ef75a4fc6b658e3256113c
parent6fd057f7960bc7b3a69f3c53de5c9d0d5d34a79c (diff)
downloadslirp-b6477f7746aadea908e1007c82bac7de44905bd6.zip
slirp-b6477f7746aadea908e1007c82bac7de44905bd6.tar.gz
slirp-b6477f7746aadea908e1007c82bac7de44905bd6.tar.bz2
slirp: Implement RFC2132 TFTP server namev3.1.0-rc0
This new usernet option can be used to add data for option 66 (tftp server name) in the BOOTP reply, which is useful in PXE based automatic OS install such as OpenBSD. Signed-off-by: Fam Zheng <famz@redhat.com> Reviewed-by: Thomas Huth <thuth@redhat.com> Tested-by: Gerd Hoffmann <kraxel@redhat.com> Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
-rw-r--r--bootp.c13
-rw-r--r--bootp.h1
-rw-r--r--libslirp.h10
-rw-r--r--slirp.c11
-rw-r--r--slirp.h1
5 files changed, 26 insertions, 10 deletions
diff --git a/bootp.c b/bootp.c
index 8ee0a61..4a27f44 100644
--- a/bootp.c
+++ b/bootp.c
@@ -323,6 +323,19 @@ static void bootp_reply(Slirp *slirp, const struct bootp_t *bp)
}
}
+ if (slirp->tftp_server_name) {
+ val = strlen(slirp->tftp_server_name);
+ if (q + val + 2 >= end) {
+ g_warning("DHCP packet size exceeded, "
+ "omitting tftp-server-name option.");
+ } else {
+ *q++ = RFC2132_TFTP_SERVER_NAME;
+ *q++ = val;
+ memcpy(q, slirp->tftp_server_name, val);
+ q += val;
+ }
+ }
+
if (slirp->vdnssearch) {
val = slirp->vdnssearch_len;
if (q + val >= end) {
diff --git a/bootp.h b/bootp.h
index 71ad7d6..f079ed5 100644
--- a/bootp.h
+++ b/bootp.h
@@ -70,6 +70,7 @@
#define RFC2132_MAX_SIZE 57
#define RFC2132_RENEWAL_TIME 58
#define RFC2132_REBIND_TIME 59
+#define RFC2132_TFTP_SERVER_NAME 66
#define DHCPDISCOVER 1
#define DHCPOFFER 2
diff --git a/libslirp.h b/libslirp.h
index eddac37..72b73a5 100644
--- a/libslirp.h
+++ b/libslirp.h
@@ -12,11 +12,11 @@ Slirp *slirp_init(int restricted, bool in_enabled, struct in_addr vnetwork,
struct in_addr vnetmask, struct in_addr vhost,
bool in6_enabled, struct in6_addr vprefix_addr6,
uint8_t vprefix_len, struct in6_addr vhost6,
- const char *vhostname, const char *tftp_path,
- const char *bootfile, struct in_addr vdhcp_start,
- struct in_addr vnameserver, struct in6_addr vnameserver6,
- const char **vdnssearch, const char *vdomainname,
- void *opaque);
+ const char *vhostname, const char *tftp_server_name,
+ const char *tftp_path, const char *bootfile,
+ struct in_addr vdhcp_start, struct in_addr vnameserver,
+ struct in6_addr vnameserver6, const char **vdnssearch,
+ const char *vdomainname, void *opaque);
void slirp_cleanup(Slirp *slirp);
void slirp_pollfds_fill(GArray *pollfds, uint32_t *timeout);
diff --git a/slirp.c b/slirp.c
index d1214ca..9ff78dd 100644
--- a/slirp.c
+++ b/slirp.c
@@ -281,11 +281,11 @@ Slirp *slirp_init(int restricted, bool in_enabled, struct in_addr vnetwork,
struct in_addr vnetmask, struct in_addr vhost,
bool in6_enabled, struct in6_addr vprefix_addr6,
uint8_t vprefix_len, struct in6_addr vhost6,
- const char *vhostname, const char *tftp_path,
- const char *bootfile, struct in_addr vdhcp_start,
- struct in_addr vnameserver, struct in6_addr vnameserver6,
- const char **vdnssearch, const char *vdomainname,
- void *opaque)
+ const char *vhostname, const char *tftp_server_name,
+ const char *tftp_path, const char *bootfile,
+ struct in_addr vdhcp_start, struct in_addr vnameserver,
+ struct in6_addr vnameserver6, const char **vdnssearch,
+ const char *vdomainname, void *opaque)
{
Slirp *slirp = g_malloc0(sizeof(Slirp));
@@ -320,6 +320,7 @@ Slirp *slirp_init(int restricted, bool in_enabled, struct in_addr vnetwork,
slirp->vdhcp_startaddr = vdhcp_start;
slirp->vnameserver_addr = vnameserver;
slirp->vnameserver_addr6 = vnameserver6;
+ slirp->tftp_server_name = g_strdup(tftp_server_name);
if (vdnssearch) {
translate_dnssearch(slirp, vdnssearch);
diff --git a/slirp.h b/slirp.h
index 318bd52..fd37678 100644
--- a/slirp.h
+++ b/slirp.h
@@ -212,6 +212,7 @@ struct Slirp {
/* tftp states */
char *tftp_prefix;
struct tftp_session tftp_sessions[TFTP_SESSIONS_MAX];
+ char *tftp_server_name;
ArpTable arp_table;
NdpTable ndp_table;