minor cleanup for packet socket type filter

SVN-Revision: 15467
This commit is contained in:
Felix Fietkau 2009-04-28 10:59:20 +00:00
parent c4a32c388c
commit f87df4b361
2 changed files with 12 additions and 12 deletions

View file

@ -11,7 +11,7 @@ Signed-off-by: Felix Fietkau <nbd@openwrt.org>
/* These ones are invisible by user level */
#define PACKET_LOOPBACK 5 /* MC/BRD frame looped back */
#define PACKET_FASTROUTE 6 /* Fastrouted frame */
+#define PACKET_ANY 0xffffffff
+#define PACKET_MASK_ANY 0xffffffff /* mask for packet type bits */
+
/* Packet socket options */
@ -30,7 +30,7 @@ Signed-off-by: Felix Fietkau <nbd@openwrt.org>
unsigned int tp_hdrlen;
unsigned int tp_reserve;
#endif
+ int pkt_type;
+ unsigned int pkt_type;
};
struct packet_skb_cb {
@ -95,7 +95,7 @@ Signed-off-by: Felix Fietkau <nbd@openwrt.org>
spin_lock_init(&po->bind_lock);
mutex_init(&po->pg_vec_lock);
po->prot_hook.func = packet_rcv;
+ po->pkt_type = PACKET_ANY & ~PACKET_LOOPBACK;
+ po->pkt_type = PACKET_MASK_ANY & ~PACKET_LOOPBACK;
if (sock->type == SOCK_PACKET)
po->prot_hook.func = packet_rcv_spkt;
@ -105,7 +105,7 @@ Signed-off-by: Felix Fietkau <nbd@openwrt.org>
}
+ case PACKET_RECV_TYPE:
+ {
+ int val;
+ unsigned int val;
+ if (optlen != sizeof(val))
+ return -EINVAL;
+ if (copy_from_user(&val, optval, sizeof(val)))
@ -121,8 +121,8 @@ Signed-off-by: Felix Fietkau <nbd@openwrt.org>
data = &val;
break;
+ case PACKET_RECV_TYPE:
+ if (len > sizeof(int))
+ len = sizeof(int);
+ if (len > sizeof(unsigned int))
+ len = sizeof(unsigned int);
+ val = po->pkt_type;
+
+ data = &val;

View file

@ -11,7 +11,7 @@ Signed-off-by: Felix Fietkau <nbd@openwrt.org>
/* These ones are invisible by user level */
#define PACKET_LOOPBACK 5 /* MC/BRD frame looped back */
#define PACKET_FASTROUTE 6 /* Fastrouted frame */
+#define PACKET_ANY 0xffffffff
+#define PACKET_MASK_ANY 0xffffffff /* mask for packet type bits */
+
/* Packet socket options */
@ -30,7 +30,7 @@ Signed-off-by: Felix Fietkau <nbd@openwrt.org>
unsigned int tp_hdrlen;
unsigned int tp_reserve;
#endif
+ int pkt_type;
+ unsigned int pkt_type;
};
struct packet_skb_cb {
@ -95,7 +95,7 @@ Signed-off-by: Felix Fietkau <nbd@openwrt.org>
spin_lock_init(&po->bind_lock);
mutex_init(&po->pg_vec_lock);
po->prot_hook.func = packet_rcv;
+ po->pkt_type = PACKET_ANY & ~PACKET_LOOPBACK;
+ po->pkt_type = PACKET_MASK_ANY & ~PACKET_LOOPBACK;
if (sock->type == SOCK_PACKET)
po->prot_hook.func = packet_rcv_spkt;
@ -105,7 +105,7 @@ Signed-off-by: Felix Fietkau <nbd@openwrt.org>
}
+ case PACKET_RECV_TYPE:
+ {
+ int val;
+ unsigned int val;
+ if (optlen != sizeof(val))
+ return -EINVAL;
+ if (copy_from_user(&val, optval, sizeof(val)))
@ -121,8 +121,8 @@ Signed-off-by: Felix Fietkau <nbd@openwrt.org>
data = &val;
break;
+ case PACKET_RECV_TYPE:
+ if (len > sizeof(int))
+ len = sizeof(int);
+ if (len > sizeof(unsigned int))
+ len = sizeof(unsigned int);
+ val = po->pkt_type;
+
+ data = &val;