From 241f650807162d169285ae4e461e7bc35798c14c Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Tue, 3 Mar 2009 13:39:23 -0800 Subject: [PATCH] datapath: Fix build on 2.6.18 (both upstream and RHEL/Xen variants). --- acinclude.m4 | 11 ++ datapath/datapath.c | 8 +- datapath/linux-2.6/Modules.mk | 5 + .../compat-2.6/include/linux/kernel.h | 9 + .../linux-2.6/compat-2.6/include/linux/log2.h | 162 ++++++++++++++++++ .../compat-2.6/include/linux/netdevice.h | 10 ++ .../compat-2.6/include/linux/percpu.h | 10 ++ .../compat-2.6/include/linux/rtnetlink.h | 24 +++ 8 files changed, 236 insertions(+), 3 deletions(-) create mode 100644 datapath/linux-2.6/compat-2.6/include/linux/kernel.h create mode 100644 datapath/linux-2.6/compat-2.6/include/linux/log2.h create mode 100644 datapath/linux-2.6/compat-2.6/include/linux/percpu.h create mode 100644 datapath/linux-2.6/compat-2.6/include/linux/rtnetlink.h diff --git a/acinclude.m4 b/acinclude.m4 index c9c9f7a1..1fc71f4b 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -108,6 +108,16 @@ AC_DEFUN([OFP_CHECK_VETH], [ fi ]) +AC_DEFUN([OFP_CHECK_LOG2_H], [ + AC_MSG_CHECKING([for $KSRC26/include/linux/log2.h]) + if test -e $KSRC26/include/linux/log2.h; then + AC_MSG_RESULT([yes]) + OFP_DEFINE([HAVE_LOG2_H]) + else + AC_MSG_RESULT([no]) + fi +]) + dnl OFP_CHECK_LINUX26_COMPAT dnl dnl Runs various Autoconf checks on the Linux 2.6 kernel source in @@ -125,6 +135,7 @@ AC_DEFUN([OFP_CHECK_LINUX26_COMPAT], [ [OFP_DEFINE([HAVE_SKB_COPY_FROM_LINEAR_DATA_OFFSET])]) OFP_GREP_IFELSE([$KSRC26/include/net/netlink.h], [NLA_NUL_STRING], [OFP_DEFINE([HAVE_NLA_NUL_STRING])]) + OFP_CHECK_LOG2_H OFP_CHECK_VETH if cmp -s datapath/linux-2.6/kcompat.h.new \ datapath/linux-2.6/kcompat.h >/dev/null 2>&1; then diff --git a/datapath/datapath.c b/datapath/datapath.c index b034e17c..9581e792 100644 --- a/datapath/datapath.c +++ b/datapath/datapath.c @@ -22,6 +22,8 @@ #include #include #include +#include +#include #include #include #include @@ -1255,7 +1257,7 @@ get_port_group(struct datapath *dp, struct odp_port_group *upg) static long openflow_ioctl(struct file *f, unsigned int cmd, unsigned long argp) { - int dp_idx = iminor(f->f_path.dentry->d_inode); + int dp_idx = iminor(f->f_dentry->d_inode); struct datapath *dp; int drop_frags, listeners, port_no; #ifdef SUPPORT_SNAT @@ -1405,7 +1407,7 @@ ssize_t openflow_read(struct file *f, char __user *buf, size_t nbytes, loff_t *ppos) { int listeners = (int) f->private_data; - int dp_idx = iminor(f->f_path.dentry->d_inode); + int dp_idx = iminor(f->f_dentry->d_inode); struct datapath *dp = get_dp(dp_idx); struct sk_buff *skb; struct iovec __user iov; @@ -1458,7 +1460,7 @@ error: static unsigned int openflow_poll(struct file *file, poll_table *wait) { - int dp_idx = iminor(file->f_path.dentry->d_inode); + int dp_idx = iminor(file->f_dentry->d_inode); struct datapath *dp = get_dp(dp_idx); unsigned int mask; diff --git a/datapath/linux-2.6/Modules.mk b/datapath/linux-2.6/Modules.mk index 274eb44d..18c0749e 100644 --- a/datapath/linux-2.6/Modules.mk +++ b/datapath/linux-2.6/Modules.mk @@ -10,12 +10,17 @@ openflow_headers += \ linux-2.6/compat-2.6/include/linux/ip.h \ linux-2.6/compat-2.6/include/linux/ipv6.h \ linux-2.6/compat-2.6/include/linux/jiffies.h \ + linux-2.6/compat-2.6/include/linux/kernel.h \ + linux-2.6/compat-2.6/include/linux/log2.h \ linux-2.6/compat-2.6/include/linux/lockdep.h \ linux-2.6/compat-2.6/include/linux/mutex.h \ + linux-2.6/compat-2.6/include/linux/netdevice.h \ linux-2.6/compat-2.6/include/linux/netfilter_ipv4.h \ linux-2.6/compat-2.6/include/linux/netlink.h \ + linux-2.6/compat-2.6/include/linux/percpu.h \ linux-2.6/compat-2.6/include/linux/random.h \ linux-2.6/compat-2.6/include/linux/rculist.h \ + linux-2.6/compat-2.6/include/linux/rtnetlink.h \ linux-2.6/compat-2.6/include/linux/skbuff.h \ linux-2.6/compat-2.6/include/linux/tcp.h \ linux-2.6/compat-2.6/include/linux/timer.h \ diff --git a/datapath/linux-2.6/compat-2.6/include/linux/kernel.h b/datapath/linux-2.6/compat-2.6/include/linux/kernel.h new file mode 100644 index 00000000..9459155d --- /dev/null +++ b/datapath/linux-2.6/compat-2.6/include/linux/kernel.h @@ -0,0 +1,9 @@ +#ifndef __KERNEL_H_WRAPPER +#define __KERNEL_H_WRAPPER 1 + +#include_next +#ifndef HAVE_LOG2_H +#include +#endif + +#endif /* linux/kernel.h */ diff --git a/datapath/linux-2.6/compat-2.6/include/linux/log2.h b/datapath/linux-2.6/compat-2.6/include/linux/log2.h new file mode 100644 index 00000000..d1a339f0 --- /dev/null +++ b/datapath/linux-2.6/compat-2.6/include/linux/log2.h @@ -0,0 +1,162 @@ +#ifdef HAVE_LOG2_H +#include_next +#else +/* Integer base 2 logarithm calculation + * + * Copyright (C) 2006, 2009 Red Hat, Inc. All Rights Reserved. + * Written by David Howells (dhowells@redhat.com) + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version + * 2 of the License, or (at your option) any later version. + */ + +#ifndef _LINUX_LOG2_H +#define _LINUX_LOG2_H + +#include +#include + +/* + * deal with unrepresentable constant logarithms + */ +extern __attribute__((const, noreturn)) +int ____ilog2_NaN(void); + +/* + * non-constant log of base 2 calculators + * - the arch may override these in asm/bitops.h if they can be implemented + * more efficiently than using fls() and fls64() + * - the arch is not required to handle n==0 if implementing the fallback + */ +#ifndef CONFIG_ARCH_HAS_ILOG2_U32 +static inline __attribute__((const)) +int __ilog2_u32(u32 n) +{ + return fls(n) - 1; +} +#endif + +#ifndef CONFIG_ARCH_HAS_ILOG2_U64 +static inline __attribute__((const)) +int __ilog2_u64(u64 n) +{ + return fls64(n) - 1; +} +#endif + +/* + * round up to nearest power of two + */ +static inline __attribute__((const)) +unsigned long __roundup_pow_of_two(unsigned long n) +{ + return 1UL << fls_long(n - 1); +} + +/** + * ilog2 - log of base 2 of 32-bit or a 64-bit unsigned value + * @n - parameter + * + * constant-capable log of base 2 calculation + * - this can be used to initialise global variables from constant data, hence + * the massive ternary operator construction + * + * selects the appropriately-sized optimised version depending on sizeof(n) + */ +#define ilog2(n) \ +( \ + __builtin_constant_p(n) ? ( \ + (n) < 1 ? ____ilog2_NaN() : \ + (n) & (1ULL << 63) ? 63 : \ + (n) & (1ULL << 62) ? 62 : \ + (n) & (1ULL << 61) ? 61 : \ + (n) & (1ULL << 60) ? 60 : \ + (n) & (1ULL << 59) ? 59 : \ + (n) & (1ULL << 58) ? 58 : \ + (n) & (1ULL << 57) ? 57 : \ + (n) & (1ULL << 56) ? 56 : \ + (n) & (1ULL << 55) ? 55 : \ + (n) & (1ULL << 54) ? 54 : \ + (n) & (1ULL << 53) ? 53 : \ + (n) & (1ULL << 52) ? 52 : \ + (n) & (1ULL << 51) ? 51 : \ + (n) & (1ULL << 50) ? 50 : \ + (n) & (1ULL << 49) ? 49 : \ + (n) & (1ULL << 48) ? 48 : \ + (n) & (1ULL << 47) ? 47 : \ + (n) & (1ULL << 46) ? 46 : \ + (n) & (1ULL << 45) ? 45 : \ + (n) & (1ULL << 44) ? 44 : \ + (n) & (1ULL << 43) ? 43 : \ + (n) & (1ULL << 42) ? 42 : \ + (n) & (1ULL << 41) ? 41 : \ + (n) & (1ULL << 40) ? 40 : \ + (n) & (1ULL << 39) ? 39 : \ + (n) & (1ULL << 38) ? 38 : \ + (n) & (1ULL << 37) ? 37 : \ + (n) & (1ULL << 36) ? 36 : \ + (n) & (1ULL << 35) ? 35 : \ + (n) & (1ULL << 34) ? 34 : \ + (n) & (1ULL << 33) ? 33 : \ + (n) & (1ULL << 32) ? 32 : \ + (n) & (1ULL << 31) ? 31 : \ + (n) & (1ULL << 30) ? 30 : \ + (n) & (1ULL << 29) ? 29 : \ + (n) & (1ULL << 28) ? 28 : \ + (n) & (1ULL << 27) ? 27 : \ + (n) & (1ULL << 26) ? 26 : \ + (n) & (1ULL << 25) ? 25 : \ + (n) & (1ULL << 24) ? 24 : \ + (n) & (1ULL << 23) ? 23 : \ + (n) & (1ULL << 22) ? 22 : \ + (n) & (1ULL << 21) ? 21 : \ + (n) & (1ULL << 20) ? 20 : \ + (n) & (1ULL << 19) ? 19 : \ + (n) & (1ULL << 18) ? 18 : \ + (n) & (1ULL << 17) ? 17 : \ + (n) & (1ULL << 16) ? 16 : \ + (n) & (1ULL << 15) ? 15 : \ + (n) & (1ULL << 14) ? 14 : \ + (n) & (1ULL << 13) ? 13 : \ + (n) & (1ULL << 12) ? 12 : \ + (n) & (1ULL << 11) ? 11 : \ + (n) & (1ULL << 10) ? 10 : \ + (n) & (1ULL << 9) ? 9 : \ + (n) & (1ULL << 8) ? 8 : \ + (n) & (1ULL << 7) ? 7 : \ + (n) & (1ULL << 6) ? 6 : \ + (n) & (1ULL << 5) ? 5 : \ + (n) & (1ULL << 4) ? 4 : \ + (n) & (1ULL << 3) ? 3 : \ + (n) & (1ULL << 2) ? 2 : \ + (n) & (1ULL << 1) ? 1 : \ + (n) & (1ULL << 0) ? 0 : \ + ____ilog2_NaN() \ + ) : \ + (sizeof(n) <= 4) ? \ + __ilog2_u32(n) : \ + __ilog2_u64(n) \ + ) + +/** + * roundup_pow_of_two - round the given value up to nearest power of two + * @n - parameter + * + * round the given balue up to the nearest power of two + * - the result is undefined when n == 0 + * - this can be used to initialise global variables from constant data + */ +#define roundup_pow_of_two(n) \ +( \ + __builtin_constant_p(n) ? ( \ + (n == 1) ? 0 : \ + (1UL << (ilog2((n) - 1) + 1)) \ + ) : \ + __roundup_pow_of_two(n) \ + ) + +#endif /* _LINUX_LOG2_H */ + +#endif diff --git a/datapath/linux-2.6/compat-2.6/include/linux/netdevice.h b/datapath/linux-2.6/compat-2.6/include/linux/netdevice.h index 7abeb3bf..015c6efd 100644 --- a/datapath/linux-2.6/compat-2.6/include/linux/netdevice.h +++ b/datapath/linux-2.6/compat-2.6/include/linux/netdevice.h @@ -3,8 +3,18 @@ #include_next +struct net; + #ifndef to_net_dev #define to_net_dev(class) container_of(class, struct net_device, class_dev) #endif +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,26) +static inline +struct net *dev_net(const struct net_device *dev) +{ + return NULL; +} +#endif /* linux kernel < 2.6.26 */ + #endif diff --git a/datapath/linux-2.6/compat-2.6/include/linux/percpu.h b/datapath/linux-2.6/compat-2.6/include/linux/percpu.h new file mode 100644 index 00000000..0f68bb25 --- /dev/null +++ b/datapath/linux-2.6/compat-2.6/include/linux/percpu.h @@ -0,0 +1,10 @@ +#ifndef __LINUX_PERCPU_H_WRAPPER +#define __LINUX_PERCPU_H_WRAPPER 1 + +#include_next + +#ifndef percpu_ptr +#define percpu_ptr per_cpu_ptr +#endif + +#endif /* linux/percpu.h wrapper */ diff --git a/datapath/linux-2.6/compat-2.6/include/linux/rtnetlink.h b/datapath/linux-2.6/compat-2.6/include/linux/rtnetlink.h new file mode 100644 index 00000000..449afde3 --- /dev/null +++ b/datapath/linux-2.6/compat-2.6/include/linux/rtnetlink.h @@ -0,0 +1,24 @@ +#ifndef __RTNETLINK_WRAPPER_H +#define __RTNETLINK_WRAPPER_H 1 + +#include_next + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19) +static inline int rtnl_notify(struct sk_buff *skb, struct net *net, u32 pid, + u32 group, struct nlmsghdr *nlh, gfp_t flags) +{ + BUG_ON(nlh); /* not implemented */ + if (group) { + /* errors reported via destination sk->sk_err */ + nlmsg_multicast(rtnl, skb, 0, group); + } + return 0; +} + +static inline void rtnl_set_sk_err(struct net *net, u32 group, int error) +{ + netlink_set_err(rtnl, 0, group, error); +} +#endif /* linux kernel < 2.6.19 */ + +#endif /* linux/rtnetlink.h wrapper */ -- 2.30.2