2 * Copyright (c) 2010 Nicira Networks.
3 * Distributed under the terms of the GNU GPL version 2.
5 * Significant portions of this file may be copied from parts of the Linux
6 * kernel, by Linus Torvalds and others.
9 #include <linux/dcache.h>
10 #include <linux/etherdevice.h>
12 #include <linux/kernel.h>
13 #include <linux/list.h>
14 #include <linux/mutex.h>
15 #include <linux/percpu.h>
16 #include <linux/rtnetlink.h>
20 extern struct vport_ops netdev_vport_ops;
21 extern struct vport_ops internal_vport_ops;
22 extern struct vport_ops gre_vport_ops;
24 static struct vport_ops *base_vport_ops_list[] = {
30 static const struct vport_ops **vport_ops_list;
31 static int n_vport_types;
33 static struct hlist_head *dev_table;
34 #define VPORT_HASH_BUCKETS 1024
36 /* Both RTNL lock and vport_mutex need to be held when updating dev_table.
38 * If you use vport_locate and then perform some operations, you need to hold
39 * one of these locks if you don't want the vport to be deleted out from under
42 * If you get a reference to a vport through a dp_port, it is protected
43 * by RCU and you need to hold rcu_read_lock instead when reading.
45 * If multiple locks are taken, the hierarchy is:
50 static DEFINE_MUTEX(vport_mutex);
53 * vport_lock - acquire vport lock
55 * Acquire global vport lock. See above comment about locking requirements
56 * and specific function definitions. May sleep.
61 mutex_lock(&vport_mutex);
65 * vport_unlock - release vport lock
67 * Release lock acquired with vport_lock.
72 mutex_unlock(&vport_mutex);
75 #define ASSERT_VPORT() do { \
76 if (unlikely(!mutex_is_locked(&vport_mutex))) { \
77 printk(KERN_ERR "openvswitch: vport lock not held at %s (%d)\n", \
78 __FILE__, __LINE__); \
84 * vport_init - initialize vport subsystem
86 * Called at module load time to initialize the vport subsystem and any
87 * compiled in vport types.
95 dev_table = kzalloc(VPORT_HASH_BUCKETS * sizeof(struct hlist_head),
102 vport_ops_list = kmalloc(ARRAY_SIZE(base_vport_ops_list) *
103 sizeof(struct vport_ops *), GFP_KERNEL);
104 if (!vport_ops_list) {
106 goto error_dev_table;
109 for (i = 0; i < ARRAY_SIZE(base_vport_ops_list); i++) {
110 struct vport_ops *new_ops = base_vport_ops_list[i];
112 if (new_ops->get_stats && new_ops->flags & VPORT_F_GEN_STATS) {
113 printk(KERN_INFO "openvswitch: both get_stats() and VPORT_F_GEN_STATS defined on vport %s, dropping VPORT_F_GEN_STATS\n", new_ops->type);
114 new_ops->flags &= ~VPORT_F_GEN_STATS;
118 err = new_ops->init();
123 vport_ops_list[n_vport_types++] = new_ops;
124 else if (new_ops->flags & VPORT_F_REQUIRED) {
146 for (i = 0; i < VPORT_HASH_BUCKETS; i++) {
147 struct hlist_head *bucket = &dev_table[i];
149 struct hlist_node *node, *next;
151 hlist_for_each_entry_safe(vport, node, next, bucket, hash_node)
160 * vport_exit - shutdown vport subsystem
162 * Called at module exit time to shutdown the vport subsystem and any
163 * initialized vport types.
172 for (i = 0; i < n_vport_types; i++) {
173 if (vport_ops_list[i]->exit)
174 vport_ops_list[i]->exit();
177 kfree(vport_ops_list);
182 * vport_add - add vport device (for userspace callers)
184 * @uvport_config: New port configuration.
186 * Creates a new vport with the specified configuration (which is dependent
187 * on device type). This function is for userspace callers and assumes no
191 vport_add(const struct odp_vport_add __user *uvport_config)
193 struct odp_vport_add vport_config;
197 if (copy_from_user(&vport_config, uvport_config, sizeof(struct odp_vport_add)))
200 vport_config.port_type[VPORT_TYPE_SIZE - 1] = '\0';
201 vport_config.devname[IFNAMSIZ - 1] = '\0';
205 vport = vport_locate(vport_config.devname);
212 vport = __vport_add(vport_config.devname, vport_config.port_type,
213 vport_config.config);
217 err = PTR_ERR(vport);
225 * vport_mod - modify existing vport device (for userspace callers)
227 * @uvport_config: New configuration for vport
229 * Modifies an existing device with the specified configuration (which is
230 * dependent on device type). This function is for userspace callers and
231 * assumes no locks are held.
234 vport_mod(const struct odp_vport_mod __user *uvport_config)
236 struct odp_vport_mod vport_config;
240 if (copy_from_user(&vport_config, uvport_config, sizeof(struct odp_vport_mod)))
243 vport_config.devname[IFNAMSIZ - 1] = '\0';
247 vport = vport_locate(vport_config.devname);
254 err = __vport_mod(vport, vport_config.config);
263 * vport_del - delete existing vport device (for userspace callers)
265 * @udevname: Name of device to delete
267 * Deletes the specified device. Detaches the device from a datapath first
268 * if it is attached. Deleting the device will fail if it does not exist or it
269 * is the datapath local port. It is also possible to fail for less obvious
270 * reasons, such as lack of memory. This function is for userspace callers and
271 * assumes no locks are held.
274 vport_del(const char __user *udevname)
276 char devname[IFNAMSIZ];
278 struct dp_port *dp_port;
282 retval = strncpy_from_user(devname, udevname, IFNAMSIZ);
285 else if (retval >= IFNAMSIZ)
286 return -ENAMETOOLONG;
290 vport = vport_locate(devname);
296 dp_port = vport_get_dp_port(vport);
298 struct datapath *dp = dp_port->dp;
300 mutex_lock(&dp->mutex);
302 if (!strcmp(dp_name(dp), devname)) {
307 err = dp_detach_port(dp_port, 0);
310 mutex_unlock(&dp->mutex);
317 err = __vport_del(vport);
326 * vport_stats_get - retrieve device stats (for userspace callers)
328 * @ustats_req: Stats request parameters.
330 * Retrieves transmit, receive, and error stats for the given device. This
331 * function is for userspace callers and assumes no locks are held.
334 vport_stats_get(struct odp_vport_stats_req __user *ustats_req)
336 struct odp_vport_stats_req stats_req;
340 if (copy_from_user(&stats_req, ustats_req, sizeof(struct odp_vport_stats_req)))
343 stats_req.devname[IFNAMSIZ - 1] = '\0';
347 vport = vport_locate(stats_req.devname);
353 if (vport->ops->get_stats)
354 err = vport->ops->get_stats(vport, &stats_req.stats);
355 else if (vport->ops->flags & VPORT_F_GEN_STATS) {
358 memset(&stats_req.stats, 0, sizeof(struct odp_vport_stats));
360 for_each_possible_cpu(i) {
361 const struct vport_percpu_stats *percpu_stats;
363 percpu_stats = per_cpu_ptr(vport->percpu_stats, i);
364 stats_req.stats.rx_bytes += percpu_stats->rx_bytes;
365 stats_req.stats.rx_packets += percpu_stats->rx_packets;
366 stats_req.stats.tx_bytes += percpu_stats->tx_bytes;
367 stats_req.stats.tx_packets += percpu_stats->tx_packets;
370 spin_lock_bh(&vport->err_stats.lock);
372 stats_req.stats.rx_dropped = vport->err_stats.rx_dropped;
373 stats_req.stats.rx_errors = vport->err_stats.rx_errors
374 + vport->err_stats.rx_frame_err
375 + vport->err_stats.rx_over_err
376 + vport->err_stats.rx_crc_err;
377 stats_req.stats.rx_frame_err = vport->err_stats.rx_frame_err;
378 stats_req.stats.rx_over_err = vport->err_stats.rx_over_err;
379 stats_req.stats.rx_crc_err = vport->err_stats.rx_crc_err;
380 stats_req.stats.tx_dropped = vport->err_stats.tx_dropped;
381 stats_req.stats.tx_errors = vport->err_stats.tx_errors;
382 stats_req.stats.collisions = vport->err_stats.collisions;
384 spin_unlock_bh(&vport->err_stats.lock);
394 if (copy_to_user(ustats_req, &stats_req, sizeof(struct odp_vport_stats_req)))
401 * vport_ether_get - retrieve device Ethernet address (for userspace callers)
403 * @uvport_ether: Ethernet address request parameters.
405 * Retrieves the Ethernet address of the given device. This function is for
406 * userspace callers and assumes no locks are held.
409 vport_ether_get(struct odp_vport_ether __user *uvport_ether)
411 struct odp_vport_ether vport_ether;
415 if (copy_from_user(&vport_ether, uvport_ether, sizeof(struct odp_vport_ether)))
418 vport_ether.devname[IFNAMSIZ - 1] = '\0';
422 vport = vport_locate(vport_ether.devname);
428 memcpy(vport_ether.ether_addr, vport_get_addr(vport), ETH_ALEN);
434 if (copy_to_user(uvport_ether, &vport_ether, sizeof(struct odp_vport_ether)))
441 * vport_ether_set - set device Ethernet address (for userspace callers)
443 * @uvport_ether: Ethernet address request parameters.
445 * Sets the Ethernet address of the given device. Some devices may not support
446 * setting the Ethernet address, in which case the result will always be
447 * -EOPNOTSUPP. This function is for userspace callers and assumes no locks
451 vport_ether_set(struct odp_vport_ether __user *uvport_ether)
453 struct odp_vport_ether vport_ether;
457 if (copy_from_user(&vport_ether, uvport_ether, sizeof(struct odp_vport_ether)))
460 vport_ether.devname[IFNAMSIZ - 1] = '\0';
465 vport = vport_locate(vport_ether.devname);
471 err = vport_set_addr(vport, vport_ether.ether_addr);
480 * vport_mut_get - retrieve device MTU (for userspace callers)
482 * @uvport_mtu: MTU request parameters.
484 * Retrieves the MTU of the given device. This function is for userspace
485 * callers and assumes no locks are held.
488 vport_mtu_get(struct odp_vport_mtu __user *uvport_mtu)
490 struct odp_vport_mtu vport_mtu;
494 if (copy_from_user(&vport_mtu, uvport_mtu, sizeof(struct odp_vport_mtu)))
497 vport_mtu.devname[IFNAMSIZ - 1] = '\0';
501 vport = vport_locate(vport_mtu.devname);
507 vport_mtu.mtu = vport_get_mtu(vport);
513 if (copy_to_user(uvport_mtu, &vport_mtu, sizeof(struct odp_vport_mtu)))
520 * vport_mtu_set - set device MTU (for userspace callers)
522 * @uvport_mtu: MTU request parameters.
524 * Sets the MTU of the given device. Some devices may not support setting the
525 * MTU, in which case the result will always be -EOPNOTSUPP. This function is
526 * for userspace callers and assumes no locks are held.
529 vport_mtu_set(struct odp_vport_mtu __user *uvport_mtu)
531 struct odp_vport_mtu vport_mtu;
535 if (copy_from_user(&vport_mtu, uvport_mtu, sizeof(struct odp_vport_mtu)))
538 vport_mtu.devname[IFNAMSIZ - 1] = '\0';
543 vport = vport_locate(vport_mtu.devname);
549 err = vport_set_mtu(vport, vport_mtu.mtu);
557 static struct hlist_head *
558 hash_bucket(const char *name)
560 unsigned int hash = full_name_hash(name, strlen(name));
561 return &dev_table[hash & (VPORT_HASH_BUCKETS - 1)];
565 * vport_locate - find a port that has already been created
567 * @name: name of port to find
569 * Either RTNL or vport lock must be acquired before calling this function
570 * and held while using the found port. See the locking comments at the
574 vport_locate(const char *name)
576 struct hlist_head *bucket = hash_bucket(name);
578 struct hlist_node *node;
580 if (unlikely(!mutex_is_locked(&vport_mutex) && !rtnl_is_locked())) {
581 printk(KERN_ERR "openvswitch: neither RTNL nor vport lock held in vport_locate\n");
585 hlist_for_each_entry(vport, node, bucket, hash_node)
586 if (!strcmp(name, vport_get_name(vport)))
593 register_vport(struct vport *vport)
595 hlist_add_head(&vport->hash_node, hash_bucket(vport_get_name(vport)));
599 unregister_vport(struct vport *vport)
601 hlist_del(&vport->hash_node);
605 * vport_alloc - allocate and initialize new vport
607 * @priv_size: Size of private data area to allocate.
608 * @ops: vport device ops
610 * Allocate and initialize a new vport defined by @ops. The vport will contain
611 * a private data area of size @priv_size that can be accessed using
612 * vport_priv(). vports that are no longer needed should be released with
616 vport_alloc(int priv_size, const struct vport_ops *ops)
621 alloc_size = sizeof(struct vport);
623 alloc_size = ALIGN(alloc_size, VPORT_ALIGN);
624 alloc_size += priv_size;
627 vport = kzalloc(alloc_size, GFP_KERNEL);
629 return ERR_PTR(-ENOMEM);
633 if (vport->ops->flags & VPORT_F_GEN_STATS) {
634 vport->percpu_stats = alloc_percpu(struct vport_percpu_stats);
635 if (!vport->percpu_stats)
636 return ERR_PTR(-ENOMEM);
638 spin_lock_init(&vport->err_stats.lock);
645 * vport_free - uninitialize and free vport
647 * @vport: vport to free
649 * Frees a vport allocated with vport_alloc() when it is no longer needed.
652 vport_free(struct vport *vport)
654 if (vport->ops->flags & VPORT_F_GEN_STATS)
655 free_percpu(vport->percpu_stats);
661 * __vport_add - add vport device (for kernel callers)
663 * @name: Name of new device.
664 * @type: Type of new device (to be matched against types in registered vport
666 * @config: Device type specific configuration. Userspace pointer.
668 * Creates a new vport with the specified configuration (which is dependent
669 * on device type). Both RTNL and vport locks must be held.
672 __vport_add(const char *name, const char *type, const void __user *config)
681 for (i = 0; i < n_vport_types; i++) {
682 if (!strcmp(vport_ops_list[i]->type, type)) {
683 vport = vport_ops_list[i]->create(name, config);
685 err = PTR_ERR(vport);
689 register_vport(vport);
701 * __vport_mod - modify existing vport device (for kernel callers)
703 * @vport: vport to modify.
704 * @config: Device type specific configuration. Userspace pointer.
706 * Modifies an existing device with the specified configuration (which is
707 * dependent on device type). Both RTNL and vport locks must be held.
710 __vport_mod(struct vport *vport, const void __user *config)
715 if (vport->ops->modify)
716 return vport->ops->modify(vport, config);
722 * __vport_del - delete existing vport device (for kernel callers)
724 * @vport: vport to delete.
726 * Deletes the specified device. The device must not be currently attached to
727 * a datapath. It is possible to fail for reasons such as lack of memory.
728 * Both RTNL and vport locks must be held.
731 __vport_del(struct vport *vport)
735 BUG_ON(vport_get_dp_port(vport));
737 unregister_vport(vport);
739 return vport->ops->destroy(vport);
743 * vport_attach - attach a vport to a datapath
745 * @vport: vport to attach.
746 * @dp_port: Datapath port to attach the vport to.
748 * Attaches a vport to a specific datapath so that packets may be exchanged.
749 * Both ports must be currently unattached. @dp_port must be successfully
750 * attached to a vport before it is connected to a datapath and must not be
751 * modified while connected. RTNL lock and the appropriate DP mutex must be held.
754 vport_attach(struct vport *vport, struct dp_port *dp_port)
761 if (vport_get_dp_port(vport))
764 if (vport->ops->attach) {
767 err = vport->ops->attach(vport);
772 dp_port->vport = vport;
773 rcu_assign_pointer(vport->dp_port, dp_port);
779 * vport_detach - detach a vport from a datapath
781 * @vport: vport to detach.
783 * Detaches a vport from a datapath. May fail for a variety of reasons,
784 * including lack of memory. RTNL lock and the appropriate DP mutex must be held.
787 vport_detach(struct vport *vport)
789 struct dp_port *dp_port;
793 dp_port = vport_get_dp_port(vport);
797 dp_port->vport = NULL;
798 rcu_assign_pointer(vport->dp_port, NULL);
800 if (vport->ops->detach)
801 return vport->ops->detach(vport);
807 * vport_set_mtu - set device MTU (for kernel callers)
809 * @vport: vport on which to set MTU.
812 * Sets the MTU of the given device. Some devices may not support setting the
813 * MTU, in which case the result will always be -EOPNOTSUPP. RTNL lock must
817 vport_set_mtu(struct vport *vport, int mtu)
824 if (vport->ops->set_mtu)
825 return vport->ops->set_mtu(vport, mtu);
831 * vport_set_addr - set device Ethernet address (for kernel callers)
833 * @vport: vport on which to set Ethernet address.
834 * @addr: New address.
836 * Sets the Ethernet address of the given device. Some devices may not support
837 * setting the Ethernet address, in which case the result will always be
838 * -EOPNOTSUPP. RTNL lock must be held.
841 vport_set_addr(struct vport *vport, const unsigned char *addr)
845 if (!is_valid_ether_addr(addr))
846 return -EADDRNOTAVAIL;
848 if (vport->ops->set_addr)
849 return vport->ops->set_addr(vport, addr);
855 * vport_get_name - retrieve device name
857 * @vport: vport from which to retrieve the name.
859 * Retrieves the name of the given device. Either RTNL lock or rcu_read_lock
860 * must be held for the entire duration that the name is in use.
863 vport_get_name(const struct vport *vport)
865 return vport->ops->get_name(vport);
869 * vport_get_type - retrieve device type
871 * @vport: vport from which to retrieve the type.
873 * Retrieves the type of the given device. Either RTNL lock or rcu_read_lock
874 * must be held for the entire duration that the type is in use.
877 vport_get_type(const struct vport *vport)
879 return vport->ops->type;
883 * vport_get_addr - retrieve device Ethernet address (for kernel callers)
885 * @vport: vport from which to retrieve the Ethernet address.
887 * Retrieves the Ethernet address of the given device. Either RTNL lock or
888 * rcu_read_lock must be held for the entire duration that the Ethernet address
891 const unsigned char *
892 vport_get_addr(const struct vport *vport)
894 return vport->ops->get_addr(vport);
898 * vport_get_dp_port - retrieve attached datapath port
900 * @vport: vport from which to retrieve the datapath port.
902 * Retrieves the attached datapath port or null if not attached. Either RTNL
903 * lock or rcu_read_lock must be held for the entire duration that the datapath
904 * port is being accessed.
907 vport_get_dp_port(const struct vport *vport)
909 return rcu_dereference(vport->dp_port);
913 * vport_get_kobj - retrieve associated kobj
915 * @vport: vport from which to retrieve the associated kobj
917 * Retrieves the associated kobj or null if no kobj. The returned kobj is
918 * valid for as long as the vport exists.
921 vport_get_kobj(const struct vport *vport)
923 if (vport->ops->get_kobj)
924 return vport->ops->get_kobj(vport);
930 * vport_get_flags - retrieve device flags
932 * @vport: vport from which to retrieve the flags
934 * Retrieves the flags of the given device. Either RTNL lock or rcu_read_lock
938 vport_get_flags(const struct vport *vport)
940 return vport->ops->get_dev_flags(vport);
944 * vport_get_flags - check whether device is running
946 * @vport: vport on which to check status.
948 * Checks whether the given device is running. Either RTNL lock or
949 * rcu_read_lock must be held.
952 vport_is_running(const struct vport *vport)
954 return vport->ops->is_running(vport);
958 * vport_get_flags - retrieve device operating state
960 * @vport: vport from which to check status
962 * Retrieves the RFC2863 operstate of the given device. Either RTNL lock or
963 * rcu_read_lock must be held.
966 vport_get_operstate(const struct vport *vport)
968 return vport->ops->get_operstate(vport);
972 * vport_get_ifindex - retrieve device system interface index
974 * @vport: vport from which to retrieve index
976 * Retrieves the system interface index of the given device. Not all devices
977 * will have system indexes, in which case the index of the datapath local
978 * port is returned. Returns a negative index on error. Either RTNL lock or
979 * rcu_read_lock must be held.
982 vport_get_ifindex(const struct vport *vport)
984 const struct dp_port *dp_port;
986 if (vport->ops->get_ifindex)
987 return vport->ops->get_ifindex(vport);
989 /* If we don't actually have an ifindex, use the local port's.
990 * Userspace doesn't check it anyways. */
991 dp_port = vport_get_dp_port(vport);
995 return vport_get_ifindex(dp_port->dp->ports[ODPP_LOCAL]->vport);
999 * vport_get_iflink - retrieve device system link index
1001 * @vport: vport from which to retrieve index
1003 * Retrieves the system link index of the given device. The link is the index
1004 * of the interface on which the packet will actually be sent. In most cases
1005 * this is the same as the ifindex but may be different for tunnel devices.
1006 * Returns a negative index on error. Either RTNL lock or rcu_read_lock must
1010 vport_get_iflink(const struct vport *vport)
1012 if (vport->ops->get_iflink)
1013 return vport->ops->get_iflink(vport);
1015 /* If we don't have an iflink, use the ifindex. In most cases they
1017 return vport_get_ifindex(vport);
1021 * vport_get_mtu - retrieve device MTU (for kernel callers)
1023 * @vport: vport from which to retrieve MTU
1025 * Retrieves the MTU of the given device. Either RTNL lock or rcu_read_lock
1029 vport_get_mtu(const struct vport *vport)
1031 return vport->ops->get_mtu(vport);
1035 * vport_receive - pass up received packet to the datapath for processing
1037 * @vport: vport that received the packet
1038 * @skb: skb that was received
1040 * Must be called with rcu_read_lock and bottom halves disabled. The packet
1041 * cannot be shared and skb->data should point to the Ethernet header. The
1042 * caller must have already called compute_ip_summed() to initialize the
1043 * checksumming fields.
1046 vport_receive(struct vport *vport, struct sk_buff *skb)
1048 struct dp_port *dp_port = vport_get_dp_port(vport);
1051 vport_record_error(vport, VPORT_E_RX_DROPPED);
1057 if (vport->ops->flags & VPORT_F_GEN_STATS) {
1058 struct vport_percpu_stats *stats;
1062 stats = per_cpu_ptr(vport->percpu_stats, smp_processor_id());
1063 stats->rx_packets++;
1064 stats->rx_bytes += skb->len;
1069 if (!(vport->ops->flags & VPORT_F_TUN_ID))
1070 OVS_CB(skb)->tun_id = 0;
1072 dp_process_received_packet(dp_port, skb);
1076 * vport_send - send a packet on a device
1078 * @vport: vport on which to send the packet
1081 * Sends the given packet and returns the length of data sent. Either RTNL
1082 * lock or rcu_read_lock must be held.
1085 vport_send(struct vport *vport, struct sk_buff *skb)
1089 sent = vport->ops->send(vport, skb);
1091 if (vport->ops->flags & VPORT_F_GEN_STATS && sent > 0) {
1092 struct vport_percpu_stats *stats;
1096 stats = per_cpu_ptr(vport->percpu_stats, smp_processor_id());
1097 stats->tx_packets++;
1098 stats->tx_bytes += sent;
1107 * vport_record_error - indicate device error to generic stats layer
1109 * @vport: vport that encountered the error
1110 * @err_type: one of enum vport_err_type types to indicate the error type
1112 * If using the vport generic stats layer indicate that an error of the given
1116 vport_record_error(struct vport *vport, enum vport_err_type err_type)
1118 if (vport->ops->flags & VPORT_F_GEN_STATS) {
1120 spin_lock_bh(&vport->err_stats.lock);
1123 case VPORT_E_RX_DROPPED:
1124 vport->err_stats.rx_dropped++;
1127 case VPORT_E_RX_ERROR:
1128 vport->err_stats.rx_errors++;
1131 case VPORT_E_RX_FRAME:
1132 vport->err_stats.rx_frame_err++;
1135 case VPORT_E_RX_OVER:
1136 vport->err_stats.rx_over_err++;
1139 case VPORT_E_RX_CRC:
1140 vport->err_stats.rx_crc_err++;
1143 case VPORT_E_TX_DROPPED:
1144 vport->err_stats.tx_dropped++;
1147 case VPORT_E_TX_ERROR:
1148 vport->err_stats.tx_errors++;
1151 case VPORT_E_COLLISION:
1152 vport->err_stats.collisions++;
1156 spin_unlock_bh(&vport->err_stats.lock);
1161 * vport_gen_ether_addr - generate an Ethernet address
1163 * @addr: location to store generated address
1165 * Generates a random Ethernet address for use when creating a device that
1166 * has no natural address.
1169 vport_gen_ether_addr(u8 *addr)
1171 random_ether_addr(addr);
1173 /* Set the OUI to the Nicira one. */
1178 /* Set the top bit to indicate random address. */