The Linux Channel

Videos :: Linux Kernel Network Programming

Written by: Kiran Kankipati
Published: 05-Nov-2017

 


Download/watch this video - 190 Linux Kernel IPv4 stack packet fragmentation and defragmentation APIs
[+] via HTTP - CDN - SAMP
[+] via Google Drive
[+] watch in dailymotion

Refer:
int ip_local_deliver(struct sk_buff *skb) :: http://lxr.free-electrons.com/source/net/ipv4/ip_input.c#L245
static inline bool ip_is_fragment(const struct iphdr *iph) :: http://lxr.free-electrons.com/source/include/net/ip.h#L286
int ip_defrag(struct net *net, struct sk_buff *skb, u32 user) :: http://lxr.free-electrons.com/source/net/ipv4/ip_fragment.c#L655
static int ip_finish_output(struct net *net, struct sock *sk, struct sk_buff *skb) :: http://lxr.free-electrons.com/source/net/ipv4/ip_output.c#L287
static int ip_fragment( .. ) :: http://lxr.free-electrons.com/ident?i=ip_fragment and http://lxr.free-electrons.com/source/net/ipv4/ip_output.c#L535
int ip_do_fragment( .. ) :: http://lxr.free-electrons.com/ident?i=ip_do_fragment and http://lxr.free-electrons.com/source/include/net/ip.h#L120

Linux Kernel Module to drop packets captured via netfilter hooks

Download this episode my entire kernel module sample code, make file, clean script HERE. And here is the source code for a quick reference.

/* pkt_drop.c
 * Author: Kiran Kankipati
 * Updated: 09-feb-2017
 */
#include <linux/kernel.h>
#include <linux/types.h>
#include <linux/module.h> 
#include <linux/errno.h>
#include <linux/slab.h>
#include <linux/netfilter.h>
#include <linux/netfilter_ipv4.h>
#include <linux/skbuff.h>  
#include <linux/udp.h>
#include <linux/ip.h>
#include <linux/in.h>
#include <linux/string.h>
#include <linux/init.h>
#include <linux/net.h>
#include <linux/netdevice.h>
#include <linux/socket.h>
#include <linux/sockios.h>
#include <linux/inet.h>
#include <linux/inetdevice.h>
#include <linux/netdevice.h>
#include <linux/etherdevice.h>
#include <linux/if_arp.h>
#include <linux/icmp.h>
#include <linux/netlink.h>
#include <linux/mroute.h>
#include <net/checksum.h>
#include <net/inet_ecn.h>
#include <net/xfrm.h>
#include <net/route.h>
#include <net/sock.h>
#include <net/ip.h>
#include <net/tcp.h>
#include <net/arp.h>
#include <net/udp.h>
#include <net/icmp.h>
#include <net/inetpeer.h>
#include <net/protocol.h>
#include <net/flow.h>
#include <asm/types.h>

static struct nf_hook_ops nfho_pre_routing;

unsigned int pre_routing_hook_func(void *priv, struct sk_buff *skb, const struct nf_hook_state *state)
{
	//kfree_skb(skb);  //- dont do this, this will crash your system.
	return NF_DROP; //this will drop the packet
	
	//return NF_ACCEPT; //this will accept the packet
}


static int hello_init(void)
{
	//Packet RX
	nfho_pre_routing.hook = pre_routing_hook_func;
	nfho_pre_routing.hooknum = NF_INET_PRE_ROUTING;
	nfho_pre_routing.pf = PF_INET;
	nfho_pre_routing.priority = NF_IP_PRI_FIRST;
	nf_register_hook(&nfho_pre_routing);

	return 0;
}

static void hello_exit(void) { nf_unregister_hook(&nfho_pre_routing); }

module_init(hello_init);
module_exit(hello_exit);



Suggested Topics:

Linux Kernel programming
Linux Kernel TCP Congestion Control Algorithms
20-Nov-2017
Linux Kernel struct socket and struct sock data-structure
31-Oct-2017
Linux Kernel /proc Interface
22-Feb-2017
Linux ioctl() API interface
11-Oct-2017
Linux Kernel Network Programming
05-Nov-2017
Linux Kernel Programming
05-Jul-2016
Linux Kernel sk_buff data-structure - Episode-11 to Episode-18
26-Mar-2017
Linux Kernel sk_buff data-structure - Episode-1 to Episode-10
05-Jul-2016
Linux Kernel net_device data-structure
05-Jul-2016
Linux Kernel dst_entry data-structure
04-May-2017
Linux Kernel struct ethhdr data-structure
02-Nov-2016
Linux Kernel struct iphdr data-structure
05-Jul-2016
Linux Kernel struct tcphdr data-structure
05-Jul-2016
Linux Kernel struct udphdr data-structure
05-Jul-2016
Linux Kernel Networking Sub-system
05-Jul-2016
Linux Kernel Compilation
05-Jul-2016
Linux Kernel Architecture - Generic
13-May-2017



The Linux Channel - v6.5 :: Updated: 12-Nov-2017 :: © 2017 :: Author: Kiran Kankipati
Your IP: 54.162.241.40 :: Browser: CCBot/2.0 (http://commoncrawl.org/faq/)