From: Mark McLoughlin <markmc@redhat.com>
To: qemu-devel@nongnu.org
Cc: Mark McLoughlin <markmc@redhat.com>
Subject: [Qemu-devel] [PATCH 08/15] net: move solaris code to net/tap-solaris.c
Date: Thu, 22 Oct 2009 17:49:09 +0100 [thread overview]
Message-ID: <1256230156-29652-9-git-send-email-markmc@redhat.com> (raw)
In-Reply-To: <1256230156-29652-1-git-send-email-markmc@redhat.com>
Signed-off-by: Mark McLoughlin <markmc@redhat.com>
---
Makefile | 1 +
net/tap-solaris.c | 185 +++++++++++++++++++++++++++++++++++++++++++++++++++++
net/tap.c | 168 +-----------------------------------------------
net/tap.h | 2 +
4 files changed, 191 insertions(+), 165 deletions(-)
create mode 100644 net/tap-solaris.c
diff --git a/Makefile b/Makefile
index a29c486..5918213 100644
--- a/Makefile
+++ b/Makefile
@@ -91,6 +91,7 @@ net-nested-y = queue.o checksum.o
net-nested-$(CONFIG_POSIX) += tap.o
net-nested-$(CONFIG_WIN32) += tap-win32.o
net-nested-$(CONFIG_BSD) += tap-bsd.o
+net-nested-$(CONFIG_SOLARIS) += tap-solaris.o
net-obj-y += $(addprefix net/, $(net-nested-y))
######################################################################
diff --git a/net/tap-solaris.c b/net/tap-solaris.c
new file mode 100644
index 0000000..0dd5b68
--- /dev/null
+++ b/net/tap-solaris.c
@@ -0,0 +1,185 @@
+/*
+ * QEMU System Emulator
+ *
+ * Copyright (c) 2003-2008 Fabrice Bellard
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "net/tap.h"
+
+#include <sys/stat.h>
+#include <sys/ethernet.h>
+#include <sys/sockio.h>
+#include <netinet/arp.h>
+#include <netinet/in.h>
+#include <netinet/in_systm.h>
+#include <netinet/ip.h>
+#include <netinet/ip_icmp.h> // must come after ip.h
+#include <netinet/udp.h>
+#include <netinet/tcp.h>
+#include <net/if.h>
+#include <syslog.h>
+#include <stropts.h>
+
+ssize_t tap_read_packet(int tapfd, uint8_t *buf, int maxlen)
+{
+ struct strbuf sbuf;
+ int f = 0;
+
+ sbuf.maxlen = maxlen;
+ sbuf.buf = (char *)buf;
+
+ return getmsg(tapfd, NULL, &sbuf, &f) >= 0 ? sbuf.len : -1;
+}
+
+#define TUNNEWPPA (('T'<<16) | 0x0001)
+/*
+ * Allocate TAP device, returns opened fd.
+ * Stores dev name in the first arg(must be large enough).
+ */
+static int tap_alloc(char *dev, size_t dev_size)
+{
+ int tap_fd, if_fd, ppa = -1;
+ static int ip_fd = 0;
+ char *ptr;
+
+ static int arp_fd = 0;
+ int ip_muxid, arp_muxid;
+ struct strioctl strioc_if, strioc_ppa;
+ int link_type = I_PLINK;;
+ struct lifreq ifr;
+ char actual_name[32] = "";
+
+ memset(&ifr, 0x0, sizeof(ifr));
+
+ if( *dev ){
+ ptr = dev;
+ while( *ptr && !qemu_isdigit((int)*ptr) ) ptr++;
+ ppa = atoi(ptr);
+ }
+
+ /* Check if IP device was opened */
+ if( ip_fd )
+ close(ip_fd);
+
+ TFR(ip_fd = open("/dev/udp", O_RDWR, 0));
+ if (ip_fd < 0) {
+ syslog(LOG_ERR, "Can't open /dev/ip (actually /dev/udp)");
+ return -1;
+ }
+
+ TFR(tap_fd = open("/dev/tap", O_RDWR, 0));
+ if (tap_fd < 0) {
+ syslog(LOG_ERR, "Can't open /dev/tap");
+ return -1;
+ }
+
+ /* Assign a new PPA and get its unit number. */
+ strioc_ppa.ic_cmd = TUNNEWPPA;
+ strioc_ppa.ic_timout = 0;
+ strioc_ppa.ic_len = sizeof(ppa);
+ strioc_ppa.ic_dp = (char *)&ppa;
+ if ((ppa = ioctl (tap_fd, I_STR, &strioc_ppa)) < 0)
+ syslog (LOG_ERR, "Can't assign new interface");
+
+ TFR(if_fd = open("/dev/tap", O_RDWR, 0));
+ if (if_fd < 0) {
+ syslog(LOG_ERR, "Can't open /dev/tap (2)");
+ return -1;
+ }
+ if(ioctl(if_fd, I_PUSH, "ip") < 0){
+ syslog(LOG_ERR, "Can't push IP module");
+ return -1;
+ }
+
+ if (ioctl(if_fd, SIOCGLIFFLAGS, &ifr) < 0)
+ syslog(LOG_ERR, "Can't get flags\n");
+
+ snprintf (actual_name, 32, "tap%d", ppa);
+ pstrcpy(ifr.lifr_name, sizeof(ifr.lifr_name), actual_name);
+
+ ifr.lifr_ppa = ppa;
+ /* Assign ppa according to the unit number returned by tun device */
+
+ if (ioctl (if_fd, SIOCSLIFNAME, &ifr) < 0)
+ syslog (LOG_ERR, "Can't set PPA %d", ppa);
+ if (ioctl(if_fd, SIOCGLIFFLAGS, &ifr) <0)
+ syslog (LOG_ERR, "Can't get flags\n");
+ /* Push arp module to if_fd */
+ if (ioctl (if_fd, I_PUSH, "arp") < 0)
+ syslog (LOG_ERR, "Can't push ARP module (2)");
+
+ /* Push arp module to ip_fd */
+ if (ioctl (ip_fd, I_POP, NULL) < 0)
+ syslog (LOG_ERR, "I_POP failed\n");
+ if (ioctl (ip_fd, I_PUSH, "arp") < 0)
+ syslog (LOG_ERR, "Can't push ARP module (3)\n");
+ /* Open arp_fd */
+ TFR(arp_fd = open ("/dev/tap", O_RDWR, 0));
+ if (arp_fd < 0)
+ syslog (LOG_ERR, "Can't open %s\n", "/dev/tap");
+
+ /* Set ifname to arp */
+ strioc_if.ic_cmd = SIOCSLIFNAME;
+ strioc_if.ic_timout = 0;
+ strioc_if.ic_len = sizeof(ifr);
+ strioc_if.ic_dp = (char *)𝔦
+ if (ioctl(arp_fd, I_STR, &strioc_if) < 0){
+ syslog (LOG_ERR, "Can't set ifname to arp\n");
+ }
+
+ if((ip_muxid = ioctl(ip_fd, I_LINK, if_fd)) < 0){
+ syslog(LOG_ERR, "Can't link TAP device to IP");
+ return -1;
+ }
+
+ if ((arp_muxid = ioctl (ip_fd, link_type, arp_fd)) < 0)
+ syslog (LOG_ERR, "Can't link TAP device to ARP");
+
+ close (if_fd);
+
+ memset(&ifr, 0x0, sizeof(ifr));
+ pstrcpy(ifr.lifr_name, sizeof(ifr.lifr_name), actual_name);
+ ifr.lifr_ip_muxid = ip_muxid;
+ ifr.lifr_arp_muxid = arp_muxid;
+
+ if (ioctl (ip_fd, SIOCSLIFMUXID, &ifr) < 0)
+ {
+ ioctl (ip_fd, I_PUNLINK , arp_muxid);
+ ioctl (ip_fd, I_PUNLINK, ip_muxid);
+ syslog (LOG_ERR, "Can't set multiplexor id");
+ }
+
+ snprintf(dev, dev_size, "tap%d", ppa);
+ return tap_fd;
+}
+
+int tap_open(char *ifname, int ifname_size, int *vnet_hdr, int vnet_hdr_required)
+{
+ char dev[10]="";
+ int fd;
+ if( (fd = tap_alloc(dev, sizeof(dev))) < 0 ){
+ fprintf(stderr, "Cannot allocate TAP device\n");
+ return -1;
+ }
+ pstrcpy(ifname, ifname_size, dev);
+ fcntl(fd, F_SETFL, O_NONBLOCK);
+ return fd;
+}
diff --git a/net/tap.c b/net/tap.c
index 64553ab..056fefe 100644
--- a/net/tap.c
+++ b/net/tap.c
@@ -42,22 +42,6 @@
#include "net/tap-linux.h"
#endif
-#ifdef __sun__
-#include <sys/stat.h>
-#include <sys/ethernet.h>
-#include <sys/sockio.h>
-#include <netinet/arp.h>
-#include <netinet/in.h>
-#include <netinet/in_systm.h>
-#include <netinet/ip.h>
-#include <netinet/ip_icmp.h> // must come after ip.h
-#include <netinet/udp.h>
-#include <netinet/tcp.h>
-#include <net/if.h>
-#include <syslog.h>
-#include <stropts.h>
-#endif
-
#if !defined(_AIX)
/* Maximum GSO packet size (64k) plus plenty of room for
@@ -191,19 +175,8 @@ static int tap_can_send(void *opaque)
return qemu_can_send_packet(s->vc);
}
-#ifdef __sun__
-static ssize_t tap_read_packet(int tapfd, uint8_t *buf, int maxlen)
-{
- struct strbuf sbuf;
- int f = 0;
-
- sbuf.maxlen = maxlen;
- sbuf.buf = (char *)buf;
-
- return getmsg(tapfd, NULL, &sbuf, &f) >= 0 ? sbuf.len : -1;
-}
-#else
-static ssize_t tap_read_packet(int tapfd, uint8_t *buf, int maxlen)
+#ifndef __sun__
+ssize_t tap_read_packet(int tapfd, uint8_t *buf, int maxlen)
{
return read(tapfd, buf, maxlen);
}
@@ -376,142 +349,7 @@ static TAPState *net_tap_fd_init(VLANState *vlan,
return s;
}
-#ifdef __sun__
-#define TUNNEWPPA (('T'<<16) | 0x0001)
-/*
- * Allocate TAP device, returns opened fd.
- * Stores dev name in the first arg(must be large enough).
- */
-static int tap_alloc(char *dev, size_t dev_size)
-{
- int tap_fd, if_fd, ppa = -1;
- static int ip_fd = 0;
- char *ptr;
-
- static int arp_fd = 0;
- int ip_muxid, arp_muxid;
- struct strioctl strioc_if, strioc_ppa;
- int link_type = I_PLINK;;
- struct lifreq ifr;
- char actual_name[32] = "";
-
- memset(&ifr, 0x0, sizeof(ifr));
-
- if( *dev ){
- ptr = dev;
- while( *ptr && !qemu_isdigit((int)*ptr) ) ptr++;
- ppa = atoi(ptr);
- }
-
- /* Check if IP device was opened */
- if( ip_fd )
- close(ip_fd);
-
- TFR(ip_fd = open("/dev/udp", O_RDWR, 0));
- if (ip_fd < 0) {
- syslog(LOG_ERR, "Can't open /dev/ip (actually /dev/udp)");
- return -1;
- }
-
- TFR(tap_fd = open("/dev/tap", O_RDWR, 0));
- if (tap_fd < 0) {
- syslog(LOG_ERR, "Can't open /dev/tap");
- return -1;
- }
-
- /* Assign a new PPA and get its unit number. */
- strioc_ppa.ic_cmd = TUNNEWPPA;
- strioc_ppa.ic_timout = 0;
- strioc_ppa.ic_len = sizeof(ppa);
- strioc_ppa.ic_dp = (char *)&ppa;
- if ((ppa = ioctl (tap_fd, I_STR, &strioc_ppa)) < 0)
- syslog (LOG_ERR, "Can't assign new interface");
-
- TFR(if_fd = open("/dev/tap", O_RDWR, 0));
- if (if_fd < 0) {
- syslog(LOG_ERR, "Can't open /dev/tap (2)");
- return -1;
- }
- if(ioctl(if_fd, I_PUSH, "ip") < 0){
- syslog(LOG_ERR, "Can't push IP module");
- return -1;
- }
-
- if (ioctl(if_fd, SIOCGLIFFLAGS, &ifr) < 0)
- syslog(LOG_ERR, "Can't get flags\n");
-
- snprintf (actual_name, 32, "tap%d", ppa);
- pstrcpy(ifr.lifr_name, sizeof(ifr.lifr_name), actual_name);
-
- ifr.lifr_ppa = ppa;
- /* Assign ppa according to the unit number returned by tun device */
-
- if (ioctl (if_fd, SIOCSLIFNAME, &ifr) < 0)
- syslog (LOG_ERR, "Can't set PPA %d", ppa);
- if (ioctl(if_fd, SIOCGLIFFLAGS, &ifr) <0)
- syslog (LOG_ERR, "Can't get flags\n");
- /* Push arp module to if_fd */
- if (ioctl (if_fd, I_PUSH, "arp") < 0)
- syslog (LOG_ERR, "Can't push ARP module (2)");
-
- /* Push arp module to ip_fd */
- if (ioctl (ip_fd, I_POP, NULL) < 0)
- syslog (LOG_ERR, "I_POP failed\n");
- if (ioctl (ip_fd, I_PUSH, "arp") < 0)
- syslog (LOG_ERR, "Can't push ARP module (3)\n");
- /* Open arp_fd */
- TFR(arp_fd = open ("/dev/tap", O_RDWR, 0));
- if (arp_fd < 0)
- syslog (LOG_ERR, "Can't open %s\n", "/dev/tap");
-
- /* Set ifname to arp */
- strioc_if.ic_cmd = SIOCSLIFNAME;
- strioc_if.ic_timout = 0;
- strioc_if.ic_len = sizeof(ifr);
- strioc_if.ic_dp = (char *)𝔦
- if (ioctl(arp_fd, I_STR, &strioc_if) < 0){
- syslog (LOG_ERR, "Can't set ifname to arp\n");
- }
-
- if((ip_muxid = ioctl(ip_fd, I_LINK, if_fd)) < 0){
- syslog(LOG_ERR, "Can't link TAP device to IP");
- return -1;
- }
-
- if ((arp_muxid = ioctl (ip_fd, link_type, arp_fd)) < 0)
- syslog (LOG_ERR, "Can't link TAP device to ARP");
-
- close (if_fd);
-
- memset(&ifr, 0x0, sizeof(ifr));
- pstrcpy(ifr.lifr_name, sizeof(ifr.lifr_name), actual_name);
- ifr.lifr_ip_muxid = ip_muxid;
- ifr.lifr_arp_muxid = arp_muxid;
-
- if (ioctl (ip_fd, SIOCSLIFMUXID, &ifr) < 0)
- {
- ioctl (ip_fd, I_PUNLINK , arp_muxid);
- ioctl (ip_fd, I_PUNLINK, ip_muxid);
- syslog (LOG_ERR, "Can't set multiplexor id");
- }
-
- snprintf(dev, dev_size, "tap%d", ppa);
- return tap_fd;
-}
-
-int tap_open(char *ifname, int ifname_size, int *vnet_hdr, int vnet_hdr_required)
-{
- char dev[10]="";
- int fd;
- if( (fd = tap_alloc(dev, sizeof(dev))) < 0 ){
- fprintf(stderr, "Cannot allocate TAP device\n");
- return -1;
- }
- pstrcpy(ifname, ifname_size, dev);
- fcntl(fd, F_SETFL, O_NONBLOCK);
- return fd;
-}
-#elif defined (_AIX)
+#ifdef _AIX
int tap_open(char *ifname, int ifname_size, int *vnet_hdr, int vnet_hdr_required)
{
fprintf (stderr, "no tap on AIX\n");
diff --git a/net/tap.h b/net/tap.h
index 5d32de5..5648ddd 100644
--- a/net/tap.h
+++ b/net/tap.h
@@ -36,6 +36,8 @@ int net_init_tap(QemuOpts *opts, Monitor *mon, const char *name, VLANState *vlan
int tap_open(char *ifname, int ifname_size, int *vnet_hdr, int vnet_hdr_required);
+ssize_t tap_read_packet(int tapfd, uint8_t *buf, int maxlen);
+
int tap_has_ufo(VLANClientState *vc);
int tap_has_vnet_hdr(VLANClientState *vc);
void tap_using_vnet_hdr(VLANClientState *vc, int using_vnet_hdr);
--
1.6.2.5
next prev parent reply other threads:[~2009-10-22 16:51 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-10-22 16:49 [Qemu-devel] [PATCH 00/15] Some networking code re-organization Mark McLoughlin
2009-10-22 16:49 ` [Qemu-devel] [PATCH 01/15] net: move net-queue.[ch] under net/ Mark McLoughlin
2009-10-23 16:52 ` [Qemu-devel] [PATCH 01/15 v2] " Mark McLoughlin
2009-10-22 16:49 ` [Qemu-devel] [PATCH 02/15] net: move net-checksum.c " Mark McLoughlin
2009-10-22 16:49 ` [Qemu-devel] [PATCH 03/15] net: move tap-win32.c " Mark McLoughlin
2009-10-22 16:49 ` [Qemu-devel] [PATCH 04/15] net: move more stuff into net/tap-win32.c, add net/tap.h Mark McLoughlin
2009-10-22 16:49 ` [Qemu-devel] [PATCH 05/15] net: move tap-linux.h under net/ Mark McLoughlin
2009-10-22 16:49 ` [Qemu-devel] [PATCH 06/15] net: split all the tap code out into net/tap.c Mark McLoughlin
2009-10-22 16:49 ` [Qemu-devel] [PATCH 07/15] net: split BSD tap_open() out into net/tap-bsd.c Mark McLoughlin
2009-10-22 16:49 ` Mark McLoughlin [this message]
2009-10-22 16:49 ` [Qemu-devel] [PATCH 09/15] net: move AIX code into net/tap-aix.c Mark McLoughlin
2009-10-22 16:49 ` [Qemu-devel] [PATCH 10/15] build: add CONFIG_LINUX Mark McLoughlin
2009-10-22 16:49 ` [Qemu-devel] [PATCH 11/15] net: move linux code into net/tap-linux.c Mark McLoughlin
2009-10-22 16:49 ` [Qemu-devel] [PATCH 12/15] net: move tap_set_sndbuf() to tap-linux.c Mark McLoughlin
2009-10-22 16:49 ` [Qemu-devel] [PATCH 13/15] net: move tap_probe_vnet_hdr() " Mark McLoughlin
2009-10-22 16:49 ` [Qemu-devel] [PATCH 14/15] net: move tap_set_offload() code into tap-linux.c Mark McLoughlin
2009-10-22 16:49 ` [Qemu-devel] [PATCH 15/15] net: move UFO support detection to tap-linux.c Mark McLoughlin
2009-10-22 20:34 ` [Qemu-devel] [PATCH 00/15] Some networking code re-organization Anthony Liguori
2009-10-23 9:59 ` Mark McLoughlin
2009-10-23 13:44 ` Anthony Liguori
2009-10-23 16:49 ` Mark McLoughlin
[not found] ` <m37hunntts.fsf@neno.mitica>
2009-10-23 10:00 ` [Qemu-devel] " Mark McLoughlin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1256230156-29652-9-git-send-email-markmc@redhat.com \
--to=markmc@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).