diff mbox

[v2] net: disallow to specify multicast MAC address

Message ID CAJN_NGaeoW3to8Pd0SPWMc2GWbnwW-qEnu=R2nPBTCHgtEuuNg@mail.gmail.com
State New
Headers show

Commit Message

Dmitry Krivenok Oct. 21, 2013, 8:08 a.m. UTC
Changes to v1:
1) Resolved names clash in include/net/eth.h
2) Reused is_multicast_ether_addr() from that header for MAC check.

Signed-off-by: Dmitry V. Krivenok <krivenok.dmitry@gmail.com>
---
 include/net/eth.h | 6 +++---
 net/net.c         | 6 ++++++
 2 files changed, 9 insertions(+), 3 deletions(-)

     if (nic->has_vectors) {

Comments

Jianjun Kong Oct. 27, 2013, 11:10 a.m. UTC | #1
On Mon, Oct 21, 2013 at 4:08 PM, Dmitry Krivenok
<krivenok.dmitry@gmail.com> wrote:
> Changes to v1:
> 1) Resolved names clash in include/net/eth.h
> 2) Reused is_multicast_ether_addr() from that header for MAC check.
>
> Signed-off-by: Dmitry V. Krivenok <krivenok.dmitry@gmail.com>

Reviewed-by: Amos Kong <kongjianjun@gmail.com>

> ---
>  include/net/eth.h | 6 +++---
>  net/net.c         | 6 ++++++
>  2 files changed, 9 insertions(+), 3 deletions(-)
>
> diff --git a/include/net/eth.h b/include/net/eth.h
> index 1d48e06..b3273b8 100644
> --- a/include/net/eth.h
> +++ b/include/net/eth.h
> @@ -84,7 +84,7 @@ typedef struct ip_pseudo_header {
>  } ip_pseudo_header;
>
>  /* IPv6 address */
> -struct in6_addr {
> +struct in6_address {
>      union {
>          uint8_t __u6_addr8[16];
>      } __in6_u;
> @@ -105,8 +105,8 @@ struct ip6_header {
>              uint8_t  ip6_un3_ecn;  /* 2 bits ECN, top 6 bits payload length */
>          } ip6_un3;
>      } ip6_ctlun;
> -    struct in6_addr ip6_src;     /* source address */
> -    struct in6_addr ip6_dst;     /* destination address */
> +    struct in6_address ip6_src;    /* source address */
> +    struct in6_address ip6_dst;    /* destination address */
>  };
>
>  struct ip6_ext_hdr {
...
Stefan Hajnoczi Oct. 29, 2013, 9:26 a.m. UTC | #2
On Mon, Oct 21, 2013 at 12:08:44PM +0400, Dmitry Krivenok wrote:
> Changes to v1:
> 1) Resolved names clash in include/net/eth.h
> 2) Reused is_multicast_ether_addr() from that header for MAC check.
> 
> Signed-off-by: Dmitry V. Krivenok <krivenok.dmitry@gmail.com>
> ---
>  include/net/eth.h | 6 +++---
>  net/net.c         | 6 ++++++
>  2 files changed, 9 insertions(+), 3 deletions(-)

Thanks, applied to my net tree:
https://github.com/stefanha/qemu/commits/net

Stefan
diff mbox

Patch

diff --git a/include/net/eth.h b/include/net/eth.h
index 1d48e06..b3273b8 100644
--- a/include/net/eth.h
+++ b/include/net/eth.h
@@ -84,7 +84,7 @@  typedef struct ip_pseudo_header {
 } ip_pseudo_header;

 /* IPv6 address */
-struct in6_addr {
+struct in6_address {
     union {
         uint8_t __u6_addr8[16];
     } __in6_u;
@@ -105,8 +105,8 @@  struct ip6_header {
             uint8_t  ip6_un3_ecn;  /* 2 bits ECN, top 6 bits payload length */
         } ip6_un3;
     } ip6_ctlun;
-    struct in6_addr ip6_src;     /* source address */
-    struct in6_addr ip6_dst;     /* destination address */
+    struct in6_address ip6_src;    /* source address */
+    struct in6_address ip6_dst;    /* destination address */
 };

 struct ip6_ext_hdr {
diff --git a/net/net.c b/net/net.c
index c330c9a..870d3bb 100644
--- a/net/net.c
+++ b/net/net.c
@@ -27,6 +27,7 @@ 
 #include "clients.h"
 #include "hub.h"
 #include "net/slirp.h"
+#include "net/eth.h"
 #include "util.h"

 #include "monitor/monitor.h"
@@ -689,6 +690,11 @@  static int net_init_nic(const NetClientOptions
*opts, const char *name,
         error_report("invalid syntax for ethernet address");
         return -1;
     }
+    if (nic->has_macaddr &&
+        is_multicast_ether_addr(nd->macaddr.a)) {
+        error_report("NIC cannot have multicast MAC address (odd 1st byte)");
+        return -1;
+    }
     qemu_macaddr_default_if_unset(&nd->macaddr);