centoskernel-modulerhel7

Build kernel module in CentOS 7 with changed API


I write NIC module driver and implement it base functions like ndo_open, ndo_stop, ndo_start_xmit...

Sometimes Linux Kernel API is changed in the recent versions. So macro like LINUX_VERSION_CODE helps adopt code of the module to recent Linux Kernel versions. In CentOS(RHEL) I meet that function name that changes MTU of NIC differs from vanilla Linux Kernel. In vanilla Linux Kernel v.3.10.0 it prototype is:

int         (*ndo_change_mtu)(struct net_device *dev,
                          int new_mtu);

But in the CentOS 7.6.1810 3.10.0-957.el7.x86_64 it is:

RH_KABI_RENAME(int      (*ndo_change_mtu),
               int      (*ndo_change_mtu_rh74))(struct net_device *dev,
                                                int new_mtu);

So I must to use ndo_change_mtu_rh74 instead of ndo_change_mtu which works as I expected.

Is it possible to use some macro to adopt code of the module between different Linux Kernel versions without patching code to prevent compilation errors against CentOS(RHEL) Linux Kernels?


Solution

  • Thnk's to @omajid who provides to me topic about kni: Fix build on RHEL 8. The next macro has solved my problem:

    #if (defined(RHEL_RELEASE_CODE) && \
        (RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(7, 5)))
        (RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(7, 5)) && \
        (RHEL_RELEASE_CODE < RHEL_RELEASE_VERSION(8, 0)))
    #define ndo_change_mtu ndo_change_mtu_rh74
    #endif