Revision 8e4416af net.c
b/net.c | ||
---|---|---|
1622 | 1622 |
|
1623 | 1623 |
int net_client_init(const char *device, const char *p) |
1624 | 1624 |
{ |
1625 |
static const char * const fd_params[] = { |
|
1626 |
"vlan", "name", "fd", NULL |
|
1627 |
}; |
|
1625 | 1628 |
char buf[1024]; |
1626 | 1629 |
int vlan_id, ret; |
1627 | 1630 |
VLANState *vlan; |
... | ... | |
1637 | 1640 |
name = strdup(buf); |
1638 | 1641 |
} |
1639 | 1642 |
if (!strcmp(device, "nic")) { |
1643 |
static const char * const nic_params[] = { |
|
1644 |
"vlan", "name", "macaddr", "model", NULL |
|
1645 |
}; |
|
1640 | 1646 |
NICInfo *nd; |
1641 | 1647 |
uint8_t *macaddr; |
1642 | 1648 |
int idx = nic_get_free_idx(); |
1643 | 1649 |
|
1650 |
if (check_params(buf, sizeof(buf), nic_params, p) < 0) { |
|
1651 |
fprintf(stderr, "qemu: invalid parameter '%s' in '%s'\n", |
|
1652 |
buf, p); |
|
1653 |
return -1; |
|
1654 |
} |
|
1644 | 1655 |
if (idx == -1 || nb_nics >= MAX_NICS) { |
1645 | 1656 |
fprintf(stderr, "Too Many NICs\n"); |
1646 | 1657 |
ret = -1; |
... | ... | |
1674 | 1685 |
ret = idx; |
1675 | 1686 |
} else |
1676 | 1687 |
if (!strcmp(device, "none")) { |
1688 |
if (*p != '\0') { |
|
1689 |
fprintf(stderr, "qemu: 'none' takes no parameters\n"); |
|
1690 |
return -1; |
|
1691 |
} |
|
1677 | 1692 |
/* does nothing. It is needed to signal that no network cards |
1678 | 1693 |
are wanted */ |
1679 | 1694 |
ret = 0; |
1680 | 1695 |
} else |
1681 | 1696 |
#ifdef CONFIG_SLIRP |
1682 | 1697 |
if (!strcmp(device, "user")) { |
1698 |
static const char * const slirp_params[] = { |
|
1699 |
"vlan", "name", "hostname", "restrict", "ip", NULL |
|
1700 |
}; |
|
1701 |
if (check_params(buf, sizeof(buf), slirp_params, p) < 0) { |
|
1702 |
fprintf(stderr, "qemu: invalid parameter '%s' in '%s'\n", |
|
1703 |
buf, p); |
|
1704 |
return -1; |
|
1705 |
} |
|
1683 | 1706 |
if (get_param_value(buf, sizeof(buf), "hostname", p)) { |
1684 | 1707 |
pstrcpy(slirp_hostname, sizeof(slirp_hostname), buf); |
1685 | 1708 |
} |
... | ... | |
1721 | 1744 |
#endif |
1722 | 1745 |
#ifdef _WIN32 |
1723 | 1746 |
if (!strcmp(device, "tap")) { |
1747 |
static const char * const tap_params[] = { |
|
1748 |
"vlan", "name", "ifname", NULL |
|
1749 |
}; |
|
1724 | 1750 |
char ifname[64]; |
1751 |
|
|
1752 |
if (check_params(buf, sizeof(buf), tap_params, p) < 0) { |
|
1753 |
fprintf(stderr, "qemu: invalid parameter '%s' in '%s'\n", |
|
1754 |
buf, p); |
|
1755 |
return -1; |
|
1756 |
} |
|
1725 | 1757 |
if (get_param_value(ifname, sizeof(ifname), "ifname", p) <= 0) { |
1726 | 1758 |
fprintf(stderr, "tap: no interface name\n"); |
1727 | 1759 |
ret = -1; |
... | ... | |
1738 | 1770 |
int fd; |
1739 | 1771 |
vlan->nb_host_devs++; |
1740 | 1772 |
if (get_param_value(buf, sizeof(buf), "fd", p) > 0) { |
1773 |
if (check_params(buf, sizeof(buf), fd_params, p) < 0) { |
|
1774 |
fprintf(stderr, "qemu: invalid parameter '%s' in '%s'\n", |
|
1775 |
buf, p); |
|
1776 |
return -1; |
|
1777 |
} |
|
1741 | 1778 |
fd = strtol(buf, NULL, 0); |
1742 | 1779 |
fcntl(fd, F_SETFL, O_NONBLOCK); |
1743 | 1780 |
net_tap_fd_init(vlan, device, name, fd); |
1744 | 1781 |
ret = 0; |
1745 | 1782 |
} else { |
1783 |
static const char * const tap_params[] = { |
|
1784 |
"vlan", "name", "ifname", "script", "downscript", NULL |
|
1785 |
}; |
|
1786 |
if (check_params(buf, sizeof(buf), tap_params, p) < 0) { |
|
1787 |
fprintf(stderr, "qemu: invalid parameter '%s' in '%s'\n", |
|
1788 |
buf, p); |
|
1789 |
return -1; |
|
1790 |
} |
|
1746 | 1791 |
if (get_param_value(ifname, sizeof(ifname), "ifname", p) <= 0) { |
1747 | 1792 |
ifname[0] = '\0'; |
1748 | 1793 |
} |
... | ... | |
1759 | 1804 |
if (!strcmp(device, "socket")) { |
1760 | 1805 |
if (get_param_value(buf, sizeof(buf), "fd", p) > 0) { |
1761 | 1806 |
int fd; |
1807 |
if (check_params(buf, sizeof(buf), fd_params, p) < 0) { |
|
1808 |
fprintf(stderr, "qemu: invalid parameter '%s' in '%s'\n", |
|
1809 |
buf, p); |
|
1810 |
return -1; |
|
1811 |
} |
|
1762 | 1812 |
fd = strtol(buf, NULL, 0); |
1763 | 1813 |
ret = -1; |
1764 | 1814 |
if (net_socket_fd_init(vlan, device, name, fd, 1)) |
1765 | 1815 |
ret = 0; |
1766 | 1816 |
} else if (get_param_value(buf, sizeof(buf), "listen", p) > 0) { |
1817 |
static const char * const listen_params[] = { |
|
1818 |
"vlan", "name", "listen", NULL |
|
1819 |
}; |
|
1820 |
if (check_params(buf, sizeof(buf), listen_params, p) < 0) { |
|
1821 |
fprintf(stderr, "qemu: invalid parameter '%s' in '%s'\n", |
|
1822 |
buf, p); |
|
1823 |
return -1; |
|
1824 |
} |
|
1767 | 1825 |
ret = net_socket_listen_init(vlan, device, name, buf); |
1768 | 1826 |
} else if (get_param_value(buf, sizeof(buf), "connect", p) > 0) { |
1827 |
static const char * const connect_params[] = { |
|
1828 |
"vlan", "name", "connect", NULL |
|
1829 |
}; |
|
1830 |
if (check_params(buf, sizeof(buf), connect_params, p) < 0) { |
|
1831 |
fprintf(stderr, "qemu: invalid parameter '%s' in '%s'\n", |
|
1832 |
buf, p); |
|
1833 |
return -1; |
|
1834 |
} |
|
1769 | 1835 |
ret = net_socket_connect_init(vlan, device, name, buf); |
1770 | 1836 |
} else if (get_param_value(buf, sizeof(buf), "mcast", p) > 0) { |
1837 |
static const char * const mcast_params[] = { |
|
1838 |
"vlan", "name", "mcast", NULL |
|
1839 |
}; |
|
1840 |
if (check_params(buf, sizeof(buf), mcast_params, p) < 0) { |
|
1841 |
fprintf(stderr, "qemu: invalid parameter '%s' in '%s'\n", |
|
1842 |
buf, p); |
|
1843 |
return -1; |
|
1844 |
} |
|
1771 | 1845 |
ret = net_socket_mcast_init(vlan, device, name, buf); |
1772 | 1846 |
} else { |
1773 | 1847 |
fprintf(stderr, "Unknown socket options: %s\n", p); |
... | ... | |
1778 | 1852 |
} else |
1779 | 1853 |
#ifdef CONFIG_VDE |
1780 | 1854 |
if (!strcmp(device, "vde")) { |
1855 |
static const char * const vde_params[] = { |
|
1856 |
"vlan", "name", "sock", "port", "group", "mode", NULL |
|
1857 |
}; |
|
1781 | 1858 |
char vde_sock[1024], vde_group[512]; |
1782 | 1859 |
int vde_port, vde_mode; |
1860 |
|
|
1861 |
if (check_params(buf, sizeof(buf), vde_params, p) < 0) { |
|
1862 |
fprintf(stderr, "qemu: invalid parameter '%s' in '%s'\n", |
|
1863 |
buf, p); |
|
1864 |
return -1; |
|
1865 |
} |
|
1783 | 1866 |
vlan->nb_host_devs++; |
1784 | 1867 |
if (get_param_value(vde_sock, sizeof(vde_sock), "sock", p) <= 0) { |
1785 | 1868 |
vde_sock[0] = '\0'; |
Also available in: Unified diff