提交 76fbbec9 编写于 作者: P Peter Maydell

Merge remote-tracking branch 'remotes/stefanha/tags/net-pull-request' into staging

Net patches

# gpg: Signature made Fri 27 Jun 2014 14:10:57 BST using RSA key ID 81AB73C8
# gpg: Good signature from "Stefan Hajnoczi <stefanha@redhat.com>"
# gpg:                 aka "Stefan Hajnoczi <stefanha@gmail.com>"

* remotes/stefanha/tags/net-pull-request:
  hw/net/eepro100: Implement read-only bits in MDI registers
  net: move queue number into NICPeers
  net: L2TPv3 transport
  qemu-bridge-helper: Fix fd leak in main()
Signed-off-by: NPeter Maydell <peter.maydell@linaro.org>
......@@ -180,7 +180,6 @@ PropertyInfo qdev_prop_chr = {
static int parse_netdev(DeviceState *dev, const char *str, void **ptr)
{
NICPeers *peers_ptr = (NICPeers *)ptr;
NICConf *conf = container_of(peers_ptr, NICConf, peers);
NetClientState **ncs = peers_ptr->ncs;
NetClientState *peers[MAX_QUEUE_NUM];
int queues, i = 0;
......@@ -219,7 +218,7 @@ static int parse_netdev(DeviceState *dev, const char *str, void **ptr)
ncs[i]->queue_index = i;
}
conf->queues = queues;
peers_ptr->queues = queues;
return 0;
......
......@@ -1217,7 +1217,6 @@ static void eepro100_write_mdi(EEPRO100State *s)
break;
case 1: /* Status Register */
missing("not writable");
data = s->mdimem[reg];
break;
case 2: /* PHY Identification Register (Word 1) */
case 3: /* PHY Identification Register (Word 2) */
......@@ -1230,7 +1229,8 @@ static void eepro100_write_mdi(EEPRO100State *s)
default:
missing("not implemented");
}
s->mdimem[reg] = data;
s->mdimem[reg] &= eepro100_mdi_mask[reg];
s->mdimem[reg] |= data & ~eepro100_mdi_mask[reg];
} else if (opcode == 2) {
/* MDI read */
switch (reg) {
......
......@@ -1542,7 +1542,7 @@ static void virtio_net_device_realize(DeviceState *dev, Error **errp)
virtio_init(vdev, "virtio-net", VIRTIO_ID_NET, n->config_size);
n->max_queues = MAX(n->nic_conf.queues, 1);
n->max_queues = MAX(n->nic_conf.peers.queues, 1);
n->vqs = g_malloc0(sizeof(VirtIONetQueue) * n->max_queues);
n->vqs[0].rx_vq = virtio_add_queue(vdev, 256, virtio_net_handle_rx);
n->curr_queues = 1;
......
......@@ -24,13 +24,13 @@ struct MACAddr {
typedef struct NICPeers {
NetClientState *ncs[MAX_QUEUE_NUM];
int32_t queues;
} NICPeers;
typedef struct NICConf {
MACAddr macaddr;
NICPeers peers;
int32_t bootindex;
int32_t queues;
} NICConf;
#define DEFINE_NIC_PROPERTIES(_state, _conf) \
......
......@@ -2,6 +2,7 @@ common-obj-y = net.o queue.o checksum.o util.o hub.o
common-obj-y += socket.o
common-obj-y += dump.o
common-obj-y += eth.o
common-obj-$(CONFIG_LINUX) += l2tpv3.o
common-obj-$(CONFIG_POSIX) += tap.o vhost-user.o
common-obj-$(CONFIG_LINUX) += tap-linux.o
common-obj-$(CONFIG_WIN32) += tap-win32.o
......
......@@ -47,6 +47,8 @@ int net_init_tap(const NetClientOptions *opts, const char *name,
int net_init_bridge(const NetClientOptions *opts, const char *name,
NetClientState *peer);
int net_init_l2tpv3(const NetClientOptions *opts, const char *name,
NetClientState *peer);
#ifdef CONFIG_VDE
int net_init_vde(const NetClientOptions *opts, const char *name,
NetClientState *peer);
......
此差异已折叠。
......@@ -250,7 +250,7 @@ NICState *qemu_new_nic(NetClientInfo *info,
{
NetClientState **peers = conf->peers.ncs;
NICState *nic;
int i, queues = MAX(1, conf->queues);
int i, queues = MAX(1, conf->peers.queues);
assert(info->type == NET_CLIENT_OPTIONS_KIND_NIC);
assert(info->size >= sizeof(NICState));
......@@ -363,7 +363,7 @@ void qemu_del_net_client(NetClientState *nc)
void qemu_del_nic(NICState *nic)
{
int i, queues = MAX(nic->conf->queues, 1);
int i, queues = MAX(nic->conf->peers.queues, 1);
/* If this is a peer NIC and peer has already been deleted, free it now. */
if (nic->peer_deleted) {
......@@ -806,6 +806,9 @@ static int (* const net_client_init_fun[NET_CLIENT_OPTIONS_KIND_MAX])(
#ifdef CONFIG_VHOST_NET_USED
[NET_CLIENT_OPTIONS_KIND_VHOST_USER] = net_init_vhost_user,
#endif
#ifdef CONFIG_LINUX
[NET_CLIENT_OPTIONS_KIND_L2TPV3] = net_init_l2tpv3,
#endif
};
......@@ -841,6 +844,9 @@ static int net_client_init1(const void *object, int is_netdev, Error **errp)
case NET_CLIENT_OPTIONS_KIND_HUBPORT:
#ifdef CONFIG_VHOST_NET_USED
case NET_CLIENT_OPTIONS_KIND_VHOST_USER:
#endif
#ifdef CONFIG_LINUX
case NET_CLIENT_OPTIONS_KIND_L2TPV3:
#endif
break;
......
......@@ -2039,6 +2039,62 @@
'*localaddr': 'str',
'*udp': 'str' } }
##
# @NetdevL2TPv3Options
#
# Connect the VLAN to Ethernet over L2TPv3 Static tunnel
#
# @src: source address
#
# @dst: destination address
#
# @srcport: #optional source port - mandatory for udp, optional for ip
#
# @dstport: #optional destination port - mandatory for udp, optional for ip
#
# @ipv6: #optional - force the use of ipv6
#
# @udp: #optional - use the udp version of l2tpv3 encapsulation
#
# @cookie64: #optional - use 64 bit coookies
#
# @counter: #optional have sequence counter
#
# @pincounter: #optional pin sequence counter to zero -
# workaround for buggy implementations or
# networks with packet reorder
#
# @txcookie: #optional 32 or 64 bit transmit cookie
#
# @rxcookie: #optional 32 or 64 bit receive cookie
#
# @txsession: 32 bit transmit session
#
# @rxsession: #optional 32 bit receive session - if not specified
# set to the same value as transmit
#
# @offset: #optional additional offset - allows the insertion of
# additional application-specific data before the packet payload
#
# Since 2.1
##
{ 'type': 'NetdevL2TPv3Options',
'data': {
'src': 'str',
'dst': 'str',
'*srcport': 'str',
'*dstport': 'str',
'*ipv6': 'bool',
'*udp': 'bool',
'*cookie64': 'bool',
'*counter': 'bool',
'*pincounter': 'bool',
'*txcookie': 'uint64',
'*rxcookie': 'uint64',
'txsession': 'uint32',
'*rxsession': 'uint32',
'*offset': 'uint32' } }
##
# @NetdevVdeOptions
#
......@@ -2150,6 +2206,9 @@
# A discriminated record of network device traits.
#
# Since 1.2
#
# 'l2tpv3' - since 2.1
#
##
{ 'union': 'NetClientOptions',
'data': {
......@@ -2157,6 +2216,7 @@
'nic': 'NetLegacyNicOptions',
'user': 'NetdevUserOptions',
'tap': 'NetdevTapOptions',
'l2tpv3': 'NetdevL2TPv3Options',
'socket': 'NetdevSocketOptions',
'vde': 'NetdevVdeOptions',
'dump': 'NetdevDumpOptions',
......
......@@ -229,7 +229,7 @@ int main(int argc, char **argv)
unsigned long ifargs[4];
#endif
int ifindex;
int fd, ctlfd, unixfd = -1;
int fd = -1, ctlfd = -1, unixfd = -1;
int use_vnet = 0;
int mtu;
const char *bridge = NULL;
......@@ -436,7 +436,12 @@ int main(int argc, char **argv)
/* profit! */
cleanup:
if (fd >= 0) {
close(fd);
}
if (ctlfd >= 0) {
close(ctlfd);
}
while ((acl_rule = QSIMPLEQ_FIRST(&acl_list)) != NULL) {
QSIMPLEQ_REMOVE_HEAD(&acl_list, entry);
g_free(acl_rule);
......
......@@ -1432,6 +1432,29 @@ DEF("net", HAS_ARG, QEMU_OPTION_net,
" connects a host TAP network interface to a host bridge device 'br'\n"
" (default=" DEFAULT_BRIDGE_INTERFACE ") using the program 'helper'\n"
" (default=" DEFAULT_BRIDGE_HELPER ")\n"
#endif
#ifdef __linux__
"-net l2tpv3[,vlan=n][,name=str],src=srcaddr,dst=dstaddr[,srcport=srcport][,dstport=dstport],txsession=txsession[,rxsession=rxsession][,ipv6=on/off][,udp=on/off][,cookie64=on/off][,counter][,pincounter][,txcookie=txcookie][,rxcookie=rxcookie][,offset=offset]\n"
" connect the VLAN to an Ethernet over L2TPv3 pseudowire\n"
" Linux kernel 3.3+ as well as most routers can talk\n"
" L2TPv3. This transport allows to connect a VM to a VM,\n"
" VM to a router and even VM to Host. It is a nearly-universal\n"
" standard (RFC3391). Note - this implementation uses static\n"
" pre-configured tunnels (same as the Linux kernel).\n"
" use 'src=' to specify source address\n"
" use 'dst=' to specify destination address\n"
" use 'udp=on' to specify udp encapsulation\n"
" use 'dstport=' to specify destination udp port\n"
" use 'dstport=' to specify destination udp port\n"
" use 'ipv6=on' to force v6\n"
" L2TPv3 uses cookies to prevent misconfiguration as\n"
" well as a weak security measure\n"
" use 'rxcookie=0x012345678' to specify a rxcookie\n"
" use 'txcookie=0x012345678' to specify a txcookie\n"
" use 'cookie64=on' to set cookie size to 64 bit, otherwise 32\n"
" use 'counter=off' to force a 'cut-down' L2TPv3 with no counter\n"
" use 'pincounter=on' to work around broken counter handling in peer\n"
" use 'offset=X' to add an extra offset between header and data\n"
#endif
"-net socket[,vlan=n][,name=str][,fd=h][,listen=[host]:port][,connect=host:port]\n"
" connect the vlan 'n' to another VLAN using a socket connection\n"
......@@ -1778,6 +1801,65 @@ qemu-system-i386 linux.img \
-net socket,mcast=239.192.168.1:1102,localaddr=1.2.3.4
@end example
@item -netdev l2tpv3,id=@var{id},src=@var{srcaddr},dst=@var{dstaddr}[,srcport=@var{srcport}][,dstport=@var{dstport}],txsession=@var{txsession}[,rxsession=@var{rxsession}][,ipv6][,udp][,cookie64][,counter][,pincounter][,txcookie=@var{txcookie}][,rxcookie=@var{rxcookie}][,offset=@var{offset}]
@item -net l2tpv3[,vlan=@var{n}][,name=@var{name}],src=@var{srcaddr},dst=@var{dstaddr}[,srcport=@var{srcport}][,dstport=@var{dstport}],txsession=@var{txsession}[,rxsession=@var{rxsession}][,ipv6][,udp][,cookie64][,counter][,pincounter][,txcookie=@var{txcookie}][,rxcookie=@var{rxcookie}][,offset=@var{offset}]
Connect VLAN @var{n} to L2TPv3 pseudowire. L2TPv3 (RFC3391) is a popular
protocol to transport Ethernet (and other Layer 2) data frames between
two systems. It is present in routers, firewalls and the Linux kernel
(from version 3.3 onwards).
This transport allows a VM to communicate to another VM, router or firewall directly.
@item src=@var{srcaddr}
source address (mandatory)
@item dst=@var{dstaddr}
destination address (mandatory)
@item udp
select udp encapsulation (default is ip).
@item srcport=@var{srcport}
source udp port.
@item dstport=@var{dstport}
destination udp port.
@item ipv6
force v6, otherwise defaults to v4.
@item rxcookie=@var{rxcookie}
@item txcookie=@var{txcookie}
Cookies are a weak form of security in the l2tpv3 specification.
Their function is mostly to prevent misconfiguration. By default they are 32
bit.
@item cookie64
Set cookie size to 64 bit instead of the default 32
@item counter=off
Force a 'cut-down' L2TPv3 with no counter as in
draft-mkonstan-l2tpext-keyed-ipv6-tunnel-00
@item pincounter=on
Work around broken counter handling in peer. This may also help on
networks which have packet reorder.
@item offset=@var{offset}
Add an extra offset between header and data
For example, to attach a VM running on host 4.3.2.1 via L2TPv3 to the bridge br-lan
on the remote Linux host 1.2.3.4:
@example
# Setup tunnel on linux host using raw ip as encapsulation
# on 1.2.3.4
ip l2tp add tunnel remote 4.3.2.1 local 1.2.3.4 tunnel_id 1 peer_tunnel_id 1 \
encap udp udp_sport 16384 udp_dport 16384
ip l2tp add session tunnel_id 1 name vmtunnel0 session_id \
0xFFFFFFFF peer_session_id 0xFFFFFFFF
ifconfig vmtunnel0 mtu 1500
ifconfig vmtunnel0 up
brctl addif br-lan vmtunnel0
# on 4.3.2.1
# launch QEMU instance - if your network has reorder or is very lossy add ,pincounter
qemu-system-i386 linux.img -net nic -net l2tpv3,src=4.2.3.1,dst=1.2.3.4,udp,srcport=16384,dstport=16384,rxsession=0xffffffff,txsession=0xffffffff,counter
@end example
@item -netdev vde,id=@var{id}[,sock=@var{socketpath}][,port=@var{n}][,group=@var{groupname}][,mode=@var{octalmode}]
@item -net vde[,vlan=@var{n}][,name=@var{name}][,sock=@var{socketpath}] [,port=@var{n}][,group=@var{groupname}][,mode=@var{octalmode}]
Connect VLAN @var{n} to PORT @var{n} of a vde switch running on host and
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册