Commit a13a4126 authored by Jan Kiszka's avatar Jan Kiszka Committed by Anthony Liguori
Browse files

slirp: Rework internal configuration



The user mode IP stack is currently only minimally configurable /wrt to
its virtual IP addresses. This is unfortunate if some guest has a fixed
idea of which IP addresses to use.

Therefore this patch prepares the stack for fully configurable IP
addresses and masks. The user interface and default addresses remain
untouched in this step, they will be enhanced in the following patch.

Signed-off-by: default avatarJan Kiszka <jan.kiszka@siemens.com>
Signed-off-by: default avatarAnthony Liguori <aliguori@us.ibm.com>
parent ad196a9d
Loading
Loading
Loading
Loading
+10 −16
Original line number Diff line number Diff line
@@ -27,8 +27,6 @@

#define NB_ADDR 16

#define START_ADDR 15

#define LEASE_TIME (24 * 3600)

typedef struct {
@@ -64,7 +62,7 @@ static BOOTPClient *get_new_addr(struct in_addr *paddr,
 found:
    bc = &bootp_clients[i];
    bc->allocated = 1;
    paddr->s_addr = htonl(ntohl(special_addr.s_addr) | (i + START_ADDR));
    paddr->s_addr = vdhcp_startaddr.s_addr + htonl(i);
    return bc;
}

@@ -72,12 +70,12 @@ static BOOTPClient *request_addr(const struct in_addr *paddr,
                                 const uint8_t *macaddr)
{
    uint32_t req_addr = ntohl(paddr->s_addr);
    uint32_t spec_addr = ntohl(special_addr.s_addr);
    uint32_t dhcp_addr = ntohl(vdhcp_startaddr.s_addr);
    BOOTPClient *bc;

    if (req_addr >= (spec_addr | START_ADDR) &&
        req_addr < (spec_addr | (NB_ADDR + START_ADDR))) {
        bc = &bootp_clients[(req_addr & 0xff) - START_ADDR];
    if (req_addr >= dhcp_addr &&
        req_addr < (dhcp_addr + NB_ADDR)) {
        bc = &bootp_clients[req_addr - dhcp_addr];
        if (!bc->allocated || !memcmp(macaddr, bc->macaddr, 6)) {
            bc->allocated = 1;
            return bc;
@@ -99,7 +97,7 @@ static BOOTPClient *find_addr(struct in_addr *paddr, const uint8_t *macaddr)
 found:
    bc = &bootp_clients[i];
    bc->allocated = 1;
    paddr->s_addr = htonl(ntohl(special_addr.s_addr) | (i + START_ADDR));
    paddr->s_addr = vdhcp_startaddr.s_addr + htonl(i);
    return bc;
}

@@ -156,7 +154,6 @@ static void bootp_reply(const struct bootp_t *bp)
    struct mbuf *m;
    struct bootp_t *rbp;
    struct sockaddr_in saddr, daddr;
    struct in_addr dns_addr;
    const struct in_addr *preq_addr;
    int dhcp_msg_type, val;
    uint8_t *q;
@@ -218,7 +215,7 @@ static void bootp_reply(const struct bootp_t *bp)
        }
    }

    saddr.sin_addr.s_addr = htonl(ntohl(special_addr.s_addr) | CTL_ALIAS);
    saddr.sin_addr = vhost_addr;
    saddr.sin_port = htons(BOOTP_SERVER);

    daddr.sin_port = htons(BOOTP_CLIENT);
@@ -262,10 +259,8 @@ static void bootp_reply(const struct bootp_t *bp)

        *q++ = RFC1533_NETMASK;
        *q++ = 4;
        *q++ = 0xff;
        *q++ = 0xff;
        *q++ = 0xff;
        *q++ = 0x00;
        memcpy(q, &vnetwork_mask, 4);
        q += 4;

        if (!slirp_restrict) {
            *q++ = RFC1533_GATEWAY;
@@ -275,8 +270,7 @@ static void bootp_reply(const struct bootp_t *bp)

            *q++ = RFC1533_DNS;
            *q++ = 4;
            dns_addr.s_addr = htonl(ntohl(special_addr.s_addr) | CTL_DNS);
            memcpy(q, &dns_addr, 4);
            memcpy(q, &vnameserver_addr, 4);
            q += 4;
        }

slirp/ctl.h

deleted100644 → 0
+0 −7
Original line number Diff line number Diff line
#define CTL_CMD		0
#define CTL_EXEC	1
#define CTL_ALIAS	2
#define CTL_DNS		3

#define CTL_SPECIAL	"10.0.2.0"
#define CTL_LOCAL	"10.0.2.15"
+6 −9
Original line number Diff line number Diff line
@@ -110,7 +110,7 @@ icmp_input(struct mbuf *m, int hlen)
  case ICMP_ECHO:
    icp->icmp_type = ICMP_ECHOREPLY;
    ip->ip_len += hlen;	             /* since ip_input subtracts this */
    if (ip->ip_dst.s_addr == alias_addr.s_addr) {
    if (ip->ip_dst.s_addr == vhost_addr.s_addr) {
      icmp_reflect(m);
    } else {
      struct socket *so;
@@ -134,16 +134,13 @@ icmp_input(struct mbuf *m, int hlen)

      /* Send the packet */
      addr.sin_family = AF_INET;
      if ((so->so_faddr.s_addr & htonl(0xffffff00)) == special_addr.s_addr) {
      if ((so->so_faddr.s_addr & vnetwork_mask.s_addr) ==
          vnetwork_addr.s_addr) {
	/* It's an alias */
	switch(ntohl(so->so_faddr.s_addr) & 0xff) {
	case CTL_DNS:
	if (so->so_faddr.s_addr == vnameserver_addr.s_addr) {
	  addr.sin_addr = dns_addr;
	  break;
	case CTL_ALIAS:
	default:
	} else {
	  addr.sin_addr = loopback_addr;
	  break;
	}
      } else {
	addr.sin_addr = so->so_faddr;
@@ -302,7 +299,7 @@ icmp_error(struct mbuf *msrc, u_char type, u_char code, int minsize,
  ip->ip_ttl = MAXTTL;
  ip->ip_p = IPPROTO_ICMP;
  ip->ip_dst = ip->ip_src;    /* ip adresses */
  ip->ip_src = alias_addr;
  ip->ip_src = vhost_addr;

  (void ) ip_output((struct socket *)NULL, m);

+5 −4
Original line number Diff line number Diff line
@@ -134,18 +134,19 @@ ip_input(struct mbuf *m)
	}

    if (slirp_restrict) {
        if (memcmp(&ip->ip_dst.s_addr, &special_addr, 3)) {
        if ((ip->ip_dst.s_addr & vnetwork_mask.s_addr) ==
            vnetwork_addr.s_addr) {
            if (ip->ip_dst.s_addr == 0xffffffff && ip->ip_p != IPPROTO_UDP)
                goto bad;
        } else {
            int host = ntohl(ip->ip_dst.s_addr) & 0xff;
            struct ex_list *ex_ptr;

            if (host == 0xff)
            if ((ip->ip_dst.s_addr & ~vnetwork_mask.s_addr) ==
                ~vnetwork_mask.s_addr)
                goto bad;

            for (ex_ptr = exec_list; ex_ptr; ex_ptr = ex_ptr->ex_next)
                if (ex_ptr->ex_addr == host)
                if (ex_ptr->ex_addr.s_addr == ip->ip_dst.s_addr)
                    break;

            if (!ex_ptr)
+5 −4
Original line number Diff line number Diff line
@@ -32,9 +32,11 @@ extern char *slirp_tty;
extern char *exec_shell;
extern u_int curtime;
extern fd_set *global_readfds, *global_writefds, *global_xfds;
extern struct in_addr ctl_addr;
extern struct in_addr special_addr;
extern struct in_addr alias_addr;
extern struct in_addr vnetwork_addr;
extern struct in_addr vnetwork_mask;
extern struct in_addr vhost_addr;
extern struct in_addr vdhcp_startaddr;
extern struct in_addr vnameserver_addr;
extern struct in_addr our_addr;
extern struct in_addr loopback_addr;
extern struct in_addr dns_addr;
@@ -44,7 +46,6 @@ extern int towrite_max;
extern int ppp_exit;
extern int tcp_keepintvl;
extern uint8_t client_ethaddr[6];
extern const char *slirp_special_ip;
extern int slirp_restrict;
extern char *tftp_prefix;
extern char *bootp_filename;
Loading