Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iptables c++ control

I need to control inbound and outbound traffic to/from a linux box from within a C++ program. I could call iptables from within my program, but I'd much rather cut out the middle man and access the kernel API functions myself.

I believe I need to use libnfnetlink, however, I have not been able to find any API documentation or example programs.

The rules I need to construct are fairly simple - things like dropping packets with a destination port equal to X etc. I do NOT intend to write a full firewall application.

can anyone suggest a better approach, or provide a link to some documentation or example apps? I'd rather avoid reading the iptables code, but i guess I may have to, if I can't find any better resources.

like image 745
Thomi Avatar asked Aug 28 '09 15:08

Thomi


People also ask

What are the 3 type of chains in iptables?

Types of Chains of iptablesOUTPUT: OUTPUT chains used for locally produced packets, specified to be set outside. PREROUTING: PREROUTING chains are used for changing packets as these packets arrive. POSTROUTING: POSTROUTING chains are used for changing packets as these packets are leaving.

Is Nftables better than iptables?

Among the advantages of nftables over iptables is less code duplication and easier extension to new protocols.

What is difference between iptables and Netfilter?

There may be some confusion about the difference between Netfilter and iptables. Netfilter is an infrastructure; it is the basic API that the Linux 2.4 kernel offers for applications that want to view and manipulate network packets. Iptables is an interface that uses Netfilter to classify and act on packets.

Is iptables deprecated?

The ipset and iptables-nft packages have been deprecated.


1 Answers

An year back I was having the same requirement and probed around. But after contacting some open source kernel guys this is what I came to know -

The kernel APIs of iptables are not externalised, means to say, they are not documented APIs. In the sense, the APIs can change any moment. They should be used only by the iptables tool. they should not be used by the application developers.

-satish

like image 168
Satish Avatar answered Oct 14 '22 22:10

Satish