0

I'm coding a new UDP based protocol in the kernel so I just forked the UDP code to get a head start. I need some new fields in the header struct other than the existing ones. I created a new struct for this but I'm at a loss regarding where this struct is initialized to prepend to the data while sending out a udp frame by the udp_sendmsg function(which I copied from the udp code).

To be clear, I just want to change the header that udp_sendmsg() places before the data. So it should be enough to know where in the kernel code the header and data are combined.

Thank you.

1
  • You don't mention which kernel in particular but udp_sendmsg points to Linux.
    – cnicutar
    Jun 22, 2016 at 8:45

1 Answer 1

0

For IPv4 a good entry point is net/ipv4/udp.c

static int udp_send_skb(struct sk_buff *skb, struct flowi4 *fl4)
{
    [...]
    * Create a UDP header
    */
    uh = udp_hdr(skb);
    uh->source = inet->inet_sport;
    uh->dest = fl4->fl4_dport;
    uh->len = htons(len);
    uh->check = 0;

Pay particular attention to udp_hdr which merely returns a memory location into the skbuff.

static inline struct udphdr *udp_hdr(const struct sk_buff *skb)
{
    return (struct udphdr *)skb_transport_header(skb);
}
2
  • Thank you. I'd then like to create a similar function say net_protocol_hdr() which can return a pointer of the type struct new_protocol. I've already defined struct new_protocol in my header file and will include this header in file containing the definition for the function new_protocol_hdr. But then, how will the extra space for the new header fields be allocated in the skbuff? Jun 22, 2016 at 10:36
  • @GauravSuman I think you're veering into a different question altogether, off-topic here.
    – cnicutar
    Jun 22, 2016 at 10:40

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.