+# -*- autoconf -*-
+
# Copyright (c) 2008 The Board of Trustees of The Leland Stanford
# Junior University
#
! test -e "$path"/include/linux/autoconf.h; then
AC_MSG_ERROR([Linux kernel source in $path is not configured])
fi
+ m4_if($3, [2.6], [OFP_CHECK_LINUX26_COMPAT])
fi
AM_CONDITIONAL($5, test -n "$path")
])
+dnl OFP_GREP_IFELSE(FILE, REGEX, IF-MATCH, IF-NO-MATCH)
+dnl
+dnl Greps FILE for REGEX. If it matches, runs IF-MATCH, otherwise IF-NO-MATCH.
+AC_DEFUN([OFP_GREP_IFELSE], [
+ AC_MSG_CHECKING([whether $2 matches in $1])
+ grep '$2' $1 >/dev/null 2>&1
+ status=$?
+ case $status in
+ 0)
+ AC_MSG_RESULT([yes])
+ $3
+ ;;
+ 1)
+ AC_MSG_RESULT([no])
+ $4
+ ;;
+ *)
+ AC_MSG_ERROR([grep exited with status $status])
+ ;;
+ esac
+])
+
+dnl OFP_DEFINE(NAME)
+dnl
+dnl Defines NAME to 1 in kcompat.h.
+AC_DEFUN([OFP_DEFINE], [
+ echo '#define $1 1' >> datapath/linux-2.6/kcompat.h.new
+])
+
+dnl OFP_CHECK_LINUX26_COMPAT
+dnl
+dnl Runs various Autoconf checks on the Linux 2.6 kernel source in
+dnl the directory in $KSRC26.
+AC_DEFUN([OFP_CHECK_LINUX26_COMPAT], [
+ rm -f datapath/linux-2.6/kcompat.h.new
+ mkdir -p datapath/linux-2.6
+ : > datapath/linux-2.6/kcompat.h.new
+ OFP_GREP_IFELSE([$KSRC26/include/linux/skbuff.h], [skb_transport_header],
+ [OFP_DEFINE([HAVE_SKBUFF_HEADER_HELPERS])])
+ OFP_GREP_IFELSE([$KSRC26/include/linux/skbuff.h], [raw],
+ [OFP_DEFINE([HAVE_MAC_RAW])])
+ if cmp -s datapath/linux-2.6/kcompat.h.new \
+ datapath/linux-2.6/kcompat.h >/dev/null 2>&1; then
+ rm datapath/linux-2.6/kcompat.h.new
+ else
+ mv datapath/linux-2.6/kcompat.h.new datapath/linux-2.6/kcompat.h
+ fi
+])
+
dnl Checks for --enable-hw-tables and substitutes HW_TABLES to any
dnl requested hardware table modules.
AC_DEFUN([OFP_CHECK_HWTABLES],
EXTRA_CFLAGS += -DBUILDNR=\"+build$(BUILDNR)\"
endif
EXTRA_CFLAGS += -g
+EXTRA_CFLAGS += -include $(builddir)/kcompat.h
# These include directories have to go before -I$(KSRC)/include.
# NOSTDINC_FLAGS just happens to be a variable that goes in the
$(eval $(notdir $(s)): ; ln -s $(srcdir)/../$(s) $@)))
distclean: clean
+ rm -f kcompat.h
distdir: clean
install:
all: default
check: all
clean:
- rm -f *.o *.ko *_mod.* Module.symvers *.cmd
+ rm -f *.o *.ko *_mod.* Module.symvers *.cmd kcompat.h.new
for d in $(all_links); do if test -h $$d; then rm $$d; fi; done
ifneq ($(KSRC),)
#include_next <asm-generic/bug.h>
-#include <linux/version.h>
-
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
-
+#ifndef WARN_ON_ONCE
#define WARN_ON_ONCE(condition) ({ \
static int __warned; \
int __ret_warn_once = !!(condition); \
} \
unlikely(__ret_warn_once); \
})
-
-#endif /* linux kernel < 2.6.19 */
+#endif
#endif
#include_next <linux/icmp.h>
-#include <linux/version.h>
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,22)
-
-#ifdef __KERNEL__
+#ifndef HAVE_SKBUFF_HEADER_HELPERS
static inline struct icmphdr *icmp_hdr(const struct sk_buff *skb)
{
return (struct icmphdr *)skb_transport_header(skb);
}
-#endif /* __KERNEL__ */
-
-#endif /* linux kernel < 2.6.22 */
+#endif
#endif
#include_next <linux/if_arp.h>
-#include <linux/version.h>
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,22)
-
-#ifdef __KERNEL__
+#ifndef HAVE_SKBUFF_HEADER_HELPERS
#include <linux/skbuff.h>
static inline struct arphdr *arp_hdr(const struct sk_buff *skb)
{
return (struct arphdr *)skb_network_header(skb);
}
-#endif /* __KERNEL__ */
-
-#endif /* linux kernel < 2.6.22 */
+#endif /* !HAVE_SKBUFF_HEADER_HELPERS */
#endif
#include_next <linux/ip.h>
-#include <linux/version.h>
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,22)
-
-#ifdef __KERNEL__
-#include <linux/skbuff.h>
-
+#ifndef HAVE_SKBUFF_HEADER_HELPERS
static inline struct iphdr *ip_hdr(const struct sk_buff *skb)
{
return (struct iphdr *)skb_network_header(skb);
{
return ip_hdr(skb)->ihl * 4;
}
-#endif /* __KERNEL__ */
-
-#endif /* linux kernel < 2.6.22 */
+#endif /* !HAVE_SKBUFF_HEADER_HELPERS */
#endif
#include_next <linux/ipv6.h>
-#include <linux/version.h>
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,22)
-
-#ifdef __KERNEL__
-#include <linux/skbuff.h>
-
+#ifndef HAVE_SKBUFF_HEADER_HELPERS
static inline struct ipv6hdr *ipv6_hdr(const struct sk_buff *skb)
{
return (struct ipv6hdr *)skb_network_header(skb);
}
-#endif /* __KERNEL__ */
-
-#endif /* linux kernel < 2.6.22 */
+#endif
#endif
#endif
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
+#ifndef CHECKSUM_PARTIAL
/* Note that CHECKSUM_PARTIAL is not implemented, but this allows us to at
* least test against it: see update_csum() in forward.c. */
#define CHECKSUM_PARTIAL 3
+#endif
+#ifndef CHECKSUM_COMPLETE
#define CHECKSUM_COMPLETE CHECKSUM_HW
-#endif /* linux kernel < 2.6.19 */
-
-
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,22)
+#endif
+#ifdef HAVE_MAC_RAW
#define mac_header mac.raw
#define network_header nh.raw
+#endif
+#ifndef HAVE_SKBUFF_HEADER_HELPERS
static inline unsigned char *skb_transport_header(const struct sk_buff *skb)
{
return skb->h.raw;
{
memcpy(skb->data, from, len);
}
-#endif /* linux kernel < 2.6.22 */
+#endif /* !HAVE_SKBUFF_HEADER_HELPERS */
#endif
#include_next <linux/tcp.h>
-#include <linux/version.h>
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,22)
-
-#ifdef __KERNEL__
+#ifndef HAVE_SKBUFF_HEADER_HELPERS
static inline struct tcphdr *tcp_hdr(const struct sk_buff *skb)
{
return (struct tcphdr *)skb_transport_header(skb);
{
return tcp_hdr(skb)->doff * 4;
}
-#endif /* __KERNEL__ */
-
-#endif /* linux kernel < 2.6.22 */
+#endif /* !HAVE_SKBUFF_HEADER_HELPERS */
#endif
#include_next <linux/udp.h>
-#include <linux/version.h>
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,22)
-
-#ifdef __KERNEL__
+#ifndef HAVE_SKBUFF_HEADER_HELPERS
static inline struct udphdr *udp_hdr(const struct sk_buff *skb)
{
return (struct udphdr *)skb_transport_header(skb);
}
-#endif /* __KERNEL__ */
-
-
-#endif /* linux kernel < 2.6.22 */
+#endif /* HAVE_SKBUFF_HEADER_HELPERS */
#endif