Updated through tag hostap_2_5 from git://w1.fi/hostap.git
[mech_eap.git] / libeap / src / l2_packet / l2_packet_privsep.c
index 79d2968..e26ca20 100644 (file)
@@ -2,14 +2,8 @@
  * WPA Supplicant - Layer2 packet handling with privilege separation
  * Copyright (c) 2007, Jouni Malinen <j@w1.fi>
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
- * Alternatively, this software may be distributed under the terms of BSD
- * license.
- *
- * See README and COPYING for more details.
+ * This software may be distributed under the terms of the BSD license.
+ * See README for more details.
  */
 
 #include "includes.h"
@@ -50,7 +44,7 @@ static int wpa_priv_cmd(struct l2_packet_data *l2, int cmd,
        msg.msg_namelen = sizeof(l2->priv_addr);
 
        if (sendmsg(l2->fd, &msg, 0) < 0) {
-               perror("L2: sendmsg(cmd)");
+               wpa_printf(MSG_ERROR, "L2: sendmsg(cmd): %s", strerror(errno));
                return -1;
        }
 
@@ -88,7 +82,8 @@ int l2_packet_send(struct l2_packet_data *l2, const u8 *dst_addr, u16 proto,
        msg.msg_namelen = sizeof(l2->priv_addr);
 
        if (sendmsg(l2->fd, &msg, 0) < 0) {
-               perror("L2: sendmsg(packet_send)");
+               wpa_printf(MSG_ERROR, "L2: sendmsg(packet_send): %s",
+                          strerror(errno));
                return -1;
        }
 
@@ -108,7 +103,8 @@ static void l2_packet_receive(int sock, void *eloop_ctx, void *sock_ctx)
        res = recvfrom(sock, buf, sizeof(buf), 0, (struct sockaddr *) &from,
                       &fromlen);
        if (res < 0) {
-               perror("l2_packet_receive - recvfrom");
+               wpa_printf(MSG_ERROR, "l2_packet_receive - recvfrom: %s",
+                          strerror(errno));
                return;
        }
        if (res < ETH_ALEN) {
@@ -168,7 +164,7 @@ struct l2_packet_data * l2_packet_init(
 
        l2->fd = socket(PF_UNIX, SOCK_DGRAM, 0);
        if (l2->fd < 0) {
-               perror("socket(PF_UNIX)");
+               wpa_printf(MSG_ERROR, "socket(PF_UNIX): %s", strerror(errno));
                os_free(l2->own_socket_path);
                l2->own_socket_path = NULL;
                os_free(l2);
@@ -179,7 +175,8 @@ struct l2_packet_data * l2_packet_init(
        addr.sun_family = AF_UNIX;
        os_strlcpy(addr.sun_path, l2->own_socket_path, sizeof(addr.sun_path));
        if (bind(l2->fd, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
-               perror("bind(PF_UNIX)");
+               wpa_printf(MSG_ERROR, "l2-pkt-privsep: bind(PF_UNIX): %s",
+                          strerror(errno));
                goto fail;
        }
 
@@ -197,14 +194,14 @@ struct l2_packet_data * l2_packet_init(
        tv.tv_usec = 0;
        res = select(l2->fd + 1, &rfds, NULL, NULL, &tv);
        if (res < 0 && errno != EINTR) {
-               perror("select");
+               wpa_printf(MSG_ERROR, "select: %s", strerror(errno));
                goto fail;
        }
 
        if (FD_ISSET(l2->fd, &rfds)) {
                res = recv(l2->fd, reply, sizeof(reply), 0);
                if (res < 0) {
-                       perror("recv");
+                       wpa_printf(MSG_ERROR, "recv: %s", strerror(errno));
                        goto fail;
                }
        } else {
@@ -234,6 +231,18 @@ fail:
 }
 
 
+struct l2_packet_data * l2_packet_init_bridge(
+       const char *br_ifname, const char *ifname, const u8 *own_addr,
+       unsigned short protocol,
+       void (*rx_callback)(void *ctx, const u8 *src_addr,
+                           const u8 *buf, size_t len),
+       void *rx_callback_ctx, int l2_hdr)
+{
+       return l2_packet_init(br_ifname, own_addr, protocol, rx_callback,
+                             rx_callback_ctx, l2_hdr);
+}
+
+
 void l2_packet_deinit(struct l2_packet_data *l2)
 {
        if (l2 == NULL)
@@ -265,3 +274,10 @@ void l2_packet_notify_auth_start(struct l2_packet_data *l2)
 {
        wpa_priv_cmd(l2, PRIVSEP_CMD_L2_NOTIFY_AUTH_START, NULL, 0);
 }
+
+
+int l2_packet_set_packet_filter(struct l2_packet_data *l2,
+                               enum l2_packet_filter_type type)
+{
+       return -1;
+}