Skip to content

Commit

Permalink
Add support for Linux kernel 5.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Stanback authored and Brian Stanback committed Sep 21, 2019
1 parent 576ddce commit 834e244
Showing 1 changed file with 37 additions and 2 deletions.
39 changes: 37 additions & 2 deletions xt_NAT.c
Original file line number Diff line number Diff line change
Expand Up @@ -545,8 +545,12 @@ static void netflow_sendmsg(void *buffer, const int len)

static void netflow_export_pdu_v5(void)
{
struct timeval tv;
int pdusize;
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 0, 0)
struct timespec64 ts;
#else
struct timeval tv;
#endif

//printk(KERN_DEBUG "xt_NAT NEL: Forming PDU seq %d, %d records\n", pdu_seq, pdu_data_records);

Expand All @@ -556,9 +560,15 @@ static void netflow_export_pdu_v5(void)
pdu.version = htons(5);
pdu.nr_records = htons(pdu_data_records);
pdu.ts_uptime = htonl(jiffies_to_msecs(jiffies));
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 0, 0)
ktime_get_real_ts64(&ts);
pdu.ts_usecs = htonl(ts.tv_sec);
pdu.ts_unsecs = htonl(ts.tv_nsec/1000);
#else
do_gettimeofday(&tv);
pdu.ts_usecs = htonl(tv.tv_sec);
pdu.ts_usecs = htonl(tv.tv_sec);
pdu.ts_unsecs = htonl(tv.tv_usec);
#endif
pdu.seq = htonl(pdu_seq);
//pdu.v5.eng_type = 0;
pdu.eng_id = (__u8)engine_id;
Expand Down Expand Up @@ -1322,7 +1332,11 @@ nat_tg(struct sk_buff *skb, const struct xt_action_param *par)
return NF_ACCEPT;
}

#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 0, 0)
void users_cleanup_timer_callback( struct timer_list *timer )
#else
void users_cleanup_timer_callback( unsigned long data )
#endif
{
struct user_htable_ent *user;
struct hlist_head *head;
Expand Down Expand Up @@ -1372,7 +1386,11 @@ void users_cleanup_timer_callback( unsigned long data )
spin_unlock_bh(&users_timer_lock);
}

#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 0, 0)
void sessions_cleanup_timer_callback( struct timer_list *timer )
#else
void sessions_cleanup_timer_callback( unsigned long data )
#endif
{
struct nat_htable_ent *session;
struct hlist_head *head;
Expand Down Expand Up @@ -1441,7 +1459,11 @@ void sessions_cleanup_timer_callback( unsigned long data )
spin_unlock_bh(&sessions_timer_lock);
}

#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 0, 0)
void nf_send_timer_callback( struct timer_list *timer )
#else
void nf_send_timer_callback( unsigned long data )
#endif
{
spin_lock_bh(&nfsend_lock);
//printk(KERN_DEBUG "xt_NAT TIMER: Exporting netflow by timer\n");
Expand Down Expand Up @@ -1661,17 +1683,30 @@ static int __init nat_tg_init(void)
proc_create("statistics", 0644, proc_net_nat, &stat_seq_fops);

spin_lock_bh(&sessions_timer_lock);

#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 0, 0)
timer_setup( &sessions_cleanup_timer, sessions_cleanup_timer_callback, 0 );
#else
setup_timer( &sessions_cleanup_timer, sessions_cleanup_timer_callback, 0 );
#endif
mod_timer( &sessions_cleanup_timer, jiffies + msecs_to_jiffies(10 * 1000) );
spin_unlock_bh(&sessions_timer_lock);

spin_lock_bh(&users_timer_lock);
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 0, 0)
timer_setup( &users_cleanup_timer, users_cleanup_timer_callback, 0 );
#else
setup_timer( &users_cleanup_timer, users_cleanup_timer_callback, 0 );
#endif
mod_timer( &users_cleanup_timer, jiffies + msecs_to_jiffies(60 * 1000) );
spin_unlock_bh(&users_timer_lock);

spin_lock_bh(&nfsend_lock);
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 0, 0)
timer_setup( &nf_send_timer, nf_send_timer_callback, 0 );
#else
setup_timer( &nf_send_timer, nf_send_timer_callback, 0 );
#endif
mod_timer( &nf_send_timer, jiffies + msecs_to_jiffies(1000) );
spin_unlock_bh(&nfsend_lock);

Expand Down

0 comments on commit 834e244

Please sign in to comment.