Kernel compatibility for Linux kernel module development

Source: Internet
Author: User

Because the Linux kernel changes very quickly, each iteration between the data structure, the interface is likely to change, so for our write kernel module compatibility brings some problems, often in a version of the module can be compiled normally, the other module on the compilation failed, this time we need to do the kernel version compatible, Here's how to fix it:

In the kernel, there is a linux/version.h header file, there are two macros Linux_version_code and kernel_version, you can use these two macros to help complete the compatibility process, the example code is as follows:

static struct Nf_hook_ops Mrs_ops_forward = {     . Hook    = Mrs_hook_forward,     . Owner   = this_module,     . PF      = Pf_inet, #if (Linux_version_code >= kernel_version (2,6,25))     . Hooknum = Nf_inet_forward, #else     . Hooknum = Nf_ip_forward, #endif. Priority = Nf_ip_pri_first,//nf_ip_pri_raw,};

You can also nest multiple layers of # if else to support more kernel versions and get the truth out of it in practice.


Sina Weibo: @ The quiet mad persone-mail: dennis.yu (@) live.cnqq:229675152focus on the field of mobile Internet audio and video communications, welcome to exchange; This article is original, reproduced please retain the copyright and contact the author
Kamailio/opensips Technology QQ Group: 118791050

Kernel compatibility for Linux kernel module development

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.