/*
- * Copyright (c) 2011, 2013 Gaetano Catalli.
+ * Copyright (c) 2011, 2013, 2014 Gaetano Catalli.
* Copyright (c) 2013, 2014 YAMAMOTO Takashi.
*
* Licensed under the Apache License, Version 2.0 (the "License");
#include "ofpbuf.h"
#include "openflow/openflow.h"
#include "ovs-thread.h"
+#include "packet-dpif.h"
#include "packets.h"
#include "poll-loop.h"
#include "shash.h"
if (!cache_notifier_refcount) {
ret = rtbsd_notifier_register(&netdev_bsd_cache_notifier,
- netdev_bsd_cache_cb, NULL);
+ netdev_bsd_cache_cb, NULL);
if (ret) {
return ret;
}
static void
proc_pkt(u_char *args_, const struct pcap_pkthdr *hdr, const u_char *packet)
{
- struct pcap_arg *args = (struct pcap_arg *)args_;
+ struct pcap_arg *args = ALIGNED_CAST(struct pcap_arg *, args_);
if (args->size < hdr->len) {
VLOG_WARN_RL(&rl, "packet truncated");
}
static int
-netdev_bsd_rxq_recv(struct netdev_rxq *rxq_, struct ofpbuf **packet, int *c)
+netdev_bsd_rxq_recv(struct netdev_rxq *rxq_, struct dpif_packet **packets,
+ int *c)
{
struct netdev_rxq_bsd *rxq = netdev_rxq_bsd_cast(rxq_);
struct netdev *netdev = rxq->up.netdev;
+ struct dpif_packet *packet;
struct ofpbuf *buffer;
ssize_t retval;
int mtu;
mtu = ETH_PAYLOAD_MAX;
}
- buffer = ofpbuf_new_with_headroom(VLAN_ETH_HEADER_LEN + mtu, DP_NETDEV_HEADROOM);
+ packet = dpif_packet_new_with_headroom(VLAN_ETH_HEADER_LEN + mtu,
+ DP_NETDEV_HEADROOM);
+ buffer = &packet->ofpbuf;
retval = (rxq->pcap_handle
? netdev_rxq_bsd_recv_pcap(rxq, buffer)
: netdev_rxq_bsd_recv_tap(rxq, buffer));
if (retval) {
- ofpbuf_delete(buffer);
+ dpif_packet_delete(packet);
} else {
dp_packet_pad(buffer);
- packet[0] = buffer;
+ packets[0] = packet;
*c = 1;
}
return retval;
* system or a tap device.
*/
static int
-netdev_bsd_send(struct netdev *netdev_, struct ofpbuf *pkt, bool may_steal)
+netdev_bsd_send(struct netdev *netdev_, struct dpif_packet **pkts, int cnt,
+ bool may_steal)
{
struct netdev_bsd *dev = netdev_bsd_cast(netdev_);
const char *name = netdev_get_name(netdev_);
- const void *data = ofpbuf_data(pkt);
- size_t size = ofpbuf_size(pkt);
int error;
+ int i;
ovs_mutex_lock(&dev->mutex);
if (dev->tap_fd < 0 && !dev->pcap) {
error = 0;
}
- while (!error) {
- ssize_t retval;
- if (dev->tap_fd >= 0) {
- retval = write(dev->tap_fd, data, size);
- } else {
- retval = pcap_inject(dev->pcap, data, size);
- }
- if (retval < 0) {
- if (errno == EINTR) {
- continue;
+ for (i = 0; i < cnt; i++) {
+ const void *data = ofpbuf_data(&pkts[i]->ofpbuf);
+ size_t size = ofpbuf_size(&pkts[i]->ofpbuf);
+
+ while (!error) {
+ ssize_t retval;
+ if (dev->tap_fd >= 0) {
+ retval = write(dev->tap_fd, data, size);
} else {
- error = errno;
- if (error != EAGAIN) {
- VLOG_WARN_RL(&rl, "error sending Ethernet packet on %s: "
- "%s", name, ovs_strerror(error));
+ retval = pcap_inject(dev->pcap, data, size);
+ }
+ if (retval < 0) {
+ if (errno == EINTR) {
+ continue;
+ } else {
+ error = errno;
+ if (error != EAGAIN) {
+ VLOG_WARN_RL(&rl, "error sending Ethernet packet on"
+ " %s: %s", name, ovs_strerror(error));
+ }
}
+ } else if (retval != size) {
+ VLOG_WARN_RL(&rl, "sent partial Ethernet packet "
+ "(%"PRIuSIZE" bytes of "
+ "%"PRIuSIZE") on %s", retval, size, name);
+ error = EMSGSIZE;
+ } else {
+ break;
}
- } else if (retval != size) {
- VLOG_WARN_RL(&rl, "sent partial Ethernet packet (%"PRIuSIZE"d bytes of "
- "%"PRIuSIZE") on %s", retval, size, name);
- error = EMSGSIZE;
- } else {
- break;
}
}
ovs_mutex_unlock(&dev->mutex);
if (may_steal) {
- ofpbuf_delete(pkt);
+ for (i = 0; i < cnt; i++) {
+ dpif_packet_delete(pkts[i]);
+ }
}
return error;
netdev_get_name(netdev_), ovs_strerror(errno));
return errno;
} else if (!strcmp(ifmd.ifmd_name, netdev_get_name(netdev_))) {
- convert_stats(netdev, stats, &ifdr.ifdr_data);
+ convert_stats(netdev_, stats, &ifmd.ifmd_data);
break;
}
}
if (!error) {
const struct sockaddr_in *sin;
- sin = (struct sockaddr_in *) &ifr.ifr_addr;
+ sin = ALIGNED_CAST(struct sockaddr_in *, &ifr.ifr_addr);
netdev->in4 = sin->sin_addr;
netdev->cache_valid |= VALID_IN4;
error = af_inet_ifreq_ioctl(netdev_get_kernel_name(netdev_), &ifr,
for (ifa = head; ifa; ifa = ifa->ifa_next) {
if (ifa->ifa_addr->sa_family == AF_INET6 &&
!strcmp(ifa->ifa_name, netdev_name)) {
- sin6 = (struct sockaddr_in6 *)ifa->ifa_addr;
+ sin6 = ALIGNED_CAST(struct sockaddr_in6 *, ifa->ifa_addr);
if (sin6) {
memcpy(&netdev->in6, &sin6->sin6_addr, sin6->sin6_len);
netdev->cache_valid |= VALID_IN6;
if ((i == RTA_GATEWAY) && sa->sa_family == AF_INET) {
const struct sockaddr_in * const sin =
- (const struct sockaddr_in *)sa;
+ ALIGNED_CAST(const struct sockaddr_in *, sa);
*next_hop = sin->sin_addr;
gateway = true;
}
if ((i == RTA_IFP) && sa->sa_family == AF_LINK) {
const struct sockaddr_dl * const sdl =
- (const struct sockaddr_dl *)sa;
+ ALIGNED_CAST(const struct sockaddr_dl *, sa);
char *kernel_name;
kernel_name = xmemdup0(sdl->sdl_data, sdl->sdl_nlen);
for (ifa = head; ifa; ifa = ifa->ifa_next) {
if (ifa->ifa_addr->sa_family == AF_LINK) {
if (!strcmp(ifa->ifa_name, netdev_name)) {
- sdl = (struct sockaddr_dl *)ifa->ifa_addr;
+ sdl = ALIGNED_CAST(struct sockaddr_dl *, ifa->ifa_addr);
if (sdl) {
memcpy(ea, LLADDR(sdl), sdl->sdl_alen);
freeifaddrs(head);
#endif
}
+#if defined(__NetBSD__)
/* Calls ioctl() on an AF_LINK sock, passing the specified 'command' and
* 'arg'. Returns 0 if successful, otherwise a positive errno value. */
int
: ioctl(sock, command, arg) == -1 ? errno
: 0);
}
+#endif