vport: Extract common functions for virtual devices.
[sliver-openvswitch.git] / datapath / vport-generic.c
1 /*
2  * Copyright (c) 2010 Nicira Networks.
3  * Distributed under the terms of the GNU GPL version 2.
4  *
5  * Significant portions of this file may be copied from parts of the Linux
6  * kernel, by Linus Torvalds and others.
7  */
8
9 #include <linux/etherdevice.h>
10
11 #include "vport-generic.h"
12
13 void
14 vport_gen_rand_ether_addr(u8 *addr)
15 {
16         random_ether_addr(addr);
17
18         /* Set the OUI to the Nicira one. */
19         addr[0] = 0x00;
20         addr[1] = 0x23;
21         addr[2] = 0x20;
22
23         /* Set the top bit to indicate random address. */
24         addr[3] |= 0x80;
25 }
26
27 unsigned
28 vport_gen_get_dev_flags(const struct vport *vport)
29 {
30         return IFF_UP | IFF_RUNNING | IFF_LOWER_UP;
31 }
32
33 int
34 vport_gen_is_running(const struct vport *vport)
35 {
36         return 1;
37 }
38
39 unsigned char
40 vport_gen_get_operstate(const struct vport *vport)
41 {
42         return IF_OPER_UP;
43 }