LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices


Reply
  Search this Thread
Old 11-07-2022, 05:06 AM   #1
IsaccBarker
LQ Newbie
 
Registered: Nov 2022
Location: Generalized in equations, without escape!
Distribution: Arch
Posts: 14

Rep: Reputation: 0
Question Working around limited kernel constants when developing module for novel protocol?


Unsure if this is the correct forum, but nevertheless, hello all!

Sorry for the verbose title; I'm unsure what other way to put it. I'm currently writing a kernel module for a L3 network routing protocol. To allocate a socket object with sk_alloc, create an instance of the net_proto_family struct, or so on, I need to use an address family/protocol family number.

Code:
static const struct net_proto_family family_ops = {
    ...
    .family = foo,
    ...
}
Code:
sk = sk_alloc(net, foo, GFP_KERNEL, proto, kern);
These are, of course, hardcoded into the kernel. So I'm wondering what the best way to get around this is.

I could, of course, dream up a random number, but I'm willing to bet this isn't optimal. Adding 1 to the max protocol would break in the future if a new one is merged into the kernel. The best way I can think of is to patch my local kernel source tree and put in a new #define. What's the best way to do this? I'm only recently getting into kernel development, so sorry if this is a stupid question.

Regards,
 
Old 11-07-2022, 03:19 PM   #2
IsaccBarker
LQ Newbie
 
Registered: Nov 2022
Location: Generalized in equations, without escape!
Distribution: Arch
Posts: 14

Original Poster
Rep: Reputation: 0
Decided to go and modify the kernel, and it worked pretty smoothly. Out of curiosity, I decided to just try the random value approach to see what would happen, but the kernel didn't like that. Just modified include/linux/socket.h, net/socket.c, security/selinux/hooks.c, and security/selinux/include/classmap.h, and it worked fine. Solved!
 
  


Reply

Tags
kernel, module, networking



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
JavaScript: function only taking constants, no variables. :/ RHLinuxGUY Programming 8 01-19-2007 02:49 AM
c: define constants kpachopoulos Programming 5 08-19-2006 03:31 PM
LXer: Variables Won't Constants Aren't: LXer Syndicated Linux News 0 07-26-2006 04:33 PM
CSS - Constants? dushkinup Programming 1 05-02-2004 01:08 PM
How do you write binary literal constants in C? vasudevadas Programming 5 01-18-2004 07:39 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel

All times are GMT -5. The time now is 12:19 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration