/* Compatibility Linux-2.0.X <-> Linux-2.1.X * Copyright (C) 1997-2000 SpellCaster Telecommunications Inc. * $Id: vercomp.h,v 1.4 2004/08/28 23:49:31 bcrl Exp $ * Released under the GNU Public License. See LICENSE file for details. */ #ifndef VERCOMP_H #define VERCOMP_H #include #ifndef LINUX_VERSION_CODE #include #endif #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,35) #define inet6_csk_xmit(skb, flow) inet6_csk_xmit(skb, 1) #elif LINUX_VERSION_CODE < KERNEL_VERSION(3,0,0) #define inet6_csk_xmit(skb, flow) inet6_csk_xmit(skb) #endif #if LINUX_VERSION_CODE >= KERNEL_VERSION(3,1,0) #define HAVE_NET_DEVICE_OPS 1 #endif #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28) #define netdev_priv(dev) ((dev)->priv) #endif #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,23) #define kmem_cache_create(a, b, c, d, e) kmem_cache_create(a,b,c,d,e,NULL) #endif #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,10) #define kmem_cache kmem_cache_s #endif #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)) #define __user /**/ #define local_irq_save(flags) save_flags(flags) #define local_irq_restore(flags) restore_flags(flags) #define local_irq_disable() cli() #define local_irq_enable() sti() #endif #if (LINUX_VERSION_CODE < 0x02030e) #define net_device device #endif #if (LINUX_VERSION_CODE < 0x020100) #include #include static inline unsigned long copy_from_user(void *to, const void *from, unsigned long n) { int i; if ((i = verify_area(VERIFY_READ, from, n)) != 0) return i; memcpy_fromfs(to, from, n); return 0; } static inline unsigned long copy_to_user(void *to, const void *from, unsigned long n) { int i; if ((i = verify_area(VERIFY_WRITE, to, n)) != 0) return i; memcpy_tofs(to, from, n); return 0; } static inline void dev_init_buffers(struct net_device *dev) { int i; for (i=0; ibuffs[i]); } #define ioremap(x,y) vremap(x,y) #define iounmap(x) vfree(x) #define signal_pending(task) !!((task)->signal & ~(task)->blocked) #define proc_register(a,b) proc_register_dynamic(a,b) #define b_dev_kfree_skb(skb) dev_kfree_skb(skb,FREE_WRITE) #define b_dev_kfree_skb_irq(skb) b_dev_kfree_skb(skb,FREE_WRITE) #define b_kfree_skb(skb) kfree_skb(skb,FREE_READ) #define net_device_stats enet_statistics #define b_dev_queue_xmit(skb) dev_queue_xmit(skb, skb->dev, 0) #elif (LINUX_VERSION_CODE >= 0x020100 && LINUX_VERSION_CODE < 0x02032B) #include #define b_kfree_skb(skb) kfree_skb(skb) #define b_dev_kfree_skb(skb) dev_kfree_skb(skb) #define b_dev_kfree_skb_irq(skb) b_dev_kfree_skb(skb) #define b_dev_queue_xmit(skb) dev_queue_xmit(skb) #else #include #define b_kfree_skb(skb) kfree_skb(skb) #define b_dev_kfree_skb(skb) dev_kfree_skb(skb) #define b_dev_kfree_skb_irq(skb) dev_kfree_skb_irq(skb) #define b_dev_queue_xmit(skb) dev_queue_xmit(skb) #endif #if (LINUX_VERSION_CODE < 0x020125) #define test_and_clear_bit clear_bit #define test_and_set_bit set_bit #endif #if (LINUX_VERSION_CODE < 0x020212) struct wait_queue; typedef struct wait_queue *wait_queue_head_t; #define DECLARE_WAITQUEUE(wait, task) struct wait_queue wait = { task, NULL } extern inline void init_waitqueue_head(wait_queue_head_t *w) { *w = NULL; } #endif #if (LINUX_VERSION_CODE < 0x2030f) #define dev_get_by_name(net, foo) dev_get(foo) #elif LINUX_VERSION_CODE <= 0x20617 #define dev_get_by_name(net, num) dev_get_by_name(num) #endif #if (LINUX_VERSION_CODE < 0x2030f) #define dev_put(x) ((void)(x)) #endif #ifndef MODULE_LICENSE #define MODULE_LICENSE(x) /**/ #endif #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,0)) #undef MOD_INC_USE_COUNT #undef MOD_DEC_USE_COUNT #define MOD_INC_USE_COUNT (void)0 #define MOD_DEC_USE_COUNT (void)0 #define dev_init_buffers(x) ((void)(x)) #endif #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)) #define my_sk_alloc(a,b,c,d,e) sk_alloc(a,b,c) #define sk_user_data user_data #define sk_data_ready data_ready #define sk_rcvbuf rcvbuf #define sk_sndbuf sndbuf #define sk_sport sport #define sk_dport dport #define sk_protinfo protinfo.destruct_hook enum sock_flags { SOCK_DEAD, SOCK_DONE, SOCK_URGINLINE, SOCK_KEEPOPEN, SOCK_LINGER, SOCK_DESTROY, SOCK_BROADCAST, SOCK_TIMESTAMP, }; static inline void sock_set_flag(struct sock *sk, enum sock_flags flag) { if (flag == SOCK_DEAD) sk->dead = 1; else BUG(); } static inline void sock_reset_flag(struct sock *sk, enum sock_flags flag) { if (flag == SOCK_DEAD) sk->dead = 0; else BUG(); } static inline int sock_flag(struct sock *sk, enum sock_flags flag) { if (flag == SOCK_DEAD) return sk->dead; BUG(); return 0; } #elif LINUX_VERSION_CODE > KERNEL_VERSION(2,6,23) #define my_sk_alloc(a,b,c,d,e) sk_alloc(&init_net,a,b,e) #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) #define my_sk_alloc(a,b,c,d,e) sk_alloc(a,b,e,c) #else #define my_sk_alloc(a,b,c,d,e) sk_alloc(a,b,c) #endif #if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,10) #define inet_sock inet_opt #define sk_socket socket #endif #if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,21) #define skb_reset_network_header(skb) ((skb)->nh.raw = (skb)->data) #define skb_set_network_header(skb,off) ((skb)->nh.raw = (u8*)(skb)->data + (off)) #define skb_reset_mac_header(skb) ((skb)->mac.raw = (skb)->data) #define skb_reset_transport_header(skb) ((skb)->h.raw = (u8*)(skb)->data) #define skb_set_transport_header(skb,off) ((skb)->h.raw = (u8*)(skb)->data + (off)) #define skb_mac_header(skb) ((skb)->mac.raw) #endif #if LINUX_VERSION_CODE < 0x02032B #define netif_queue_stopped(dev) ((dev)->tbusy) #define netif_wake_queue(dev) do { \ clear_bit(0, &(dev)->tbusy); \ mark_bh(NET_BH); \ } while (0) #define netif_start_queue(dev) ((dev)->start = 1) #define netif_stop_queue(dev) (void)(((dev)->start = 0), set_bit(0, &(dev)->tbusy)) #endif #if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,30) #define skb_dst(skb) ((skb)->dst) #define skb_dst_set(skb,_dst) ((skb)->dst = (_dst)) #endif #if !defined(put_net) && !defined(CONFIG_NET_NS) #define put_net(net) do { (void)net; } while (0) #endif #if defined(CONFIG_NET_NS) && LINUX_VERSION_CODE < KERNEL_VERSION(2,6,32) #include /* * Must be called under rcu_read_lock() or with tasklist_lock read-held. */ static inline struct task_struct *my_find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns) { return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID); } static inline struct task_struct *my_find_task_by_vpid(pid_t vnr) { return my_find_task_by_pid_ns(vnr, current->nsproxy->pid_ns); } static inline struct net *get_net_ns_by_pid(pid_t pid) { struct task_struct *tsk; struct net *net; /* Lookup the network namespace */ net = ERR_PTR(-ESRCH); rcu_read_lock(); tsk = my_find_task_by_vpid(pid); if (tsk) { struct nsproxy *nsproxy; nsproxy = task_nsproxy(tsk); if (nsproxy) net = get_net(nsproxy->net_ns); } rcu_read_unlock(); return net; } #endif #ifndef CSUM_MANGLED_0 #define CSUM_MANGLED_0 ((u16)0xffff) #endif #ifndef ACCESS_ONCE #define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x)) #endif #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,22) && !defined(RHEL_MAJOR) static inline int skb_transport_offset(const struct sk_buff *skb) { return skb->h.raw - skb->data; } static inline void skb_set_mac_header(struct sk_buff *skb, const int offset) { skb->mac.raw = skb->data + offset; } #endif #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,26) #if defined(RHEL_MAJOR) #define proc_create_data(name, mode, parent, fops, data) \ proc_create(name, mode, parent, fops, data) #else #include static inline struct proc_dir_entry *proc_create_data(const char *name, mode_t mode, struct proc_dir_entry *parent, const struct file_operations *fops, void *data) { struct proc_dir_entry *res = create_proc_entry(name, mode, &proc_root); if (res) { res->proc_fops = fops; res->data = data; } return res; } #endif #endif #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37) #define INIT_RCU_HEAD(ptr) (void)(ptr) #endif #endif /* ifndef VERCOMP_H */