Netlink notification for iptable modification are not received to application











up vote
0
down vote

favorite












I wrote a program to listen to iptables modification through netlink sockets, for this I used NETLINK_AUDIT family, when I execute the program and modify the iptables rule, program doesn't receive any message from kernel and it will be in blocking mode only. Could you help me to find what is wrong in this program or what else I need to do to receive iptables notification.



#include "libaudit.h"
#include <stdio.h>
#include <string.h>
#include <unistd.h>

int main()
{
int rc;
struct audit_message rep;
int fd;
struct sockaddr_nl sa;

memset(&sa, 0, sizeof(sa));
sa.nl_family = AF_NETLINK;
sa.nl_groups = 0;

fd = audit_open();

bind(fd, (struct sockaddr *) &sa, sizeof(sa));

rc = audit_get_reply(fd, &rep, GET_REPLY_BLOCKING, 0);
if(rc < 0)
{
printf("Error");
}
else
{
printf("msg received %d n",rep.nlh.nlmsg_type );
break;
}


audit_close(fd);

return 0;
}









share|improve this question









New contributor




avinash is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • are you running this program as a root / privileged user ?
    – Devidas
    Nov 21 at 6:07










  • Yes,running as a root user.
    – avinash
    Nov 21 at 6:08










  • do you have auditd running ?
    – Devidas
    Nov 21 at 6:09










  • Yes. ps -eaf | grep -i auditd root 499 2 0 Nov16 ? 00:00:00 [kauditd] root 926 1 0 Nov16 ? 00:00:00 /sbin/auditd -n
    – avinash
    Nov 21 at 6:15












  • can you check return value of bind and if it is less than zero use perror or check errno ?
    – Devidas
    Nov 21 at 6:30















up vote
0
down vote

favorite












I wrote a program to listen to iptables modification through netlink sockets, for this I used NETLINK_AUDIT family, when I execute the program and modify the iptables rule, program doesn't receive any message from kernel and it will be in blocking mode only. Could you help me to find what is wrong in this program or what else I need to do to receive iptables notification.



#include "libaudit.h"
#include <stdio.h>
#include <string.h>
#include <unistd.h>

int main()
{
int rc;
struct audit_message rep;
int fd;
struct sockaddr_nl sa;

memset(&sa, 0, sizeof(sa));
sa.nl_family = AF_NETLINK;
sa.nl_groups = 0;

fd = audit_open();

bind(fd, (struct sockaddr *) &sa, sizeof(sa));

rc = audit_get_reply(fd, &rep, GET_REPLY_BLOCKING, 0);
if(rc < 0)
{
printf("Error");
}
else
{
printf("msg received %d n",rep.nlh.nlmsg_type );
break;
}


audit_close(fd);

return 0;
}









share|improve this question









New contributor




avinash is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • are you running this program as a root / privileged user ?
    – Devidas
    Nov 21 at 6:07










  • Yes,running as a root user.
    – avinash
    Nov 21 at 6:08










  • do you have auditd running ?
    – Devidas
    Nov 21 at 6:09










  • Yes. ps -eaf | grep -i auditd root 499 2 0 Nov16 ? 00:00:00 [kauditd] root 926 1 0 Nov16 ? 00:00:00 /sbin/auditd -n
    – avinash
    Nov 21 at 6:15












  • can you check return value of bind and if it is less than zero use perror or check errno ?
    – Devidas
    Nov 21 at 6:30













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I wrote a program to listen to iptables modification through netlink sockets, for this I used NETLINK_AUDIT family, when I execute the program and modify the iptables rule, program doesn't receive any message from kernel and it will be in blocking mode only. Could you help me to find what is wrong in this program or what else I need to do to receive iptables notification.



#include "libaudit.h"
#include <stdio.h>
#include <string.h>
#include <unistd.h>

int main()
{
int rc;
struct audit_message rep;
int fd;
struct sockaddr_nl sa;

memset(&sa, 0, sizeof(sa));
sa.nl_family = AF_NETLINK;
sa.nl_groups = 0;

fd = audit_open();

bind(fd, (struct sockaddr *) &sa, sizeof(sa));

rc = audit_get_reply(fd, &rep, GET_REPLY_BLOCKING, 0);
if(rc < 0)
{
printf("Error");
}
else
{
printf("msg received %d n",rep.nlh.nlmsg_type );
break;
}


audit_close(fd);

return 0;
}









share|improve this question









New contributor




avinash is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











I wrote a program to listen to iptables modification through netlink sockets, for this I used NETLINK_AUDIT family, when I execute the program and modify the iptables rule, program doesn't receive any message from kernel and it will be in blocking mode only. Could you help me to find what is wrong in this program or what else I need to do to receive iptables notification.



#include "libaudit.h"
#include <stdio.h>
#include <string.h>
#include <unistd.h>

int main()
{
int rc;
struct audit_message rep;
int fd;
struct sockaddr_nl sa;

memset(&sa, 0, sizeof(sa));
sa.nl_family = AF_NETLINK;
sa.nl_groups = 0;

fd = audit_open();

bind(fd, (struct sockaddr *) &sa, sizeof(sa));

rc = audit_get_reply(fd, &rep, GET_REPLY_BLOCKING, 0);
if(rc < 0)
{
printf("Error");
}
else
{
printf("msg received %d n",rep.nlh.nlmsg_type );
break;
}


audit_close(fd);

return 0;
}






c linux linux-kernel iptables netlink






share|improve this question









New contributor




avinash is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




avinash is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited Nov 21 at 12:02









red0ct

1,1153822




1,1153822






New contributor




avinash is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked Nov 21 at 5:52









avinash

1




1




New contributor




avinash is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





avinash is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






avinash is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












  • are you running this program as a root / privileged user ?
    – Devidas
    Nov 21 at 6:07










  • Yes,running as a root user.
    – avinash
    Nov 21 at 6:08










  • do you have auditd running ?
    – Devidas
    Nov 21 at 6:09










  • Yes. ps -eaf | grep -i auditd root 499 2 0 Nov16 ? 00:00:00 [kauditd] root 926 1 0 Nov16 ? 00:00:00 /sbin/auditd -n
    – avinash
    Nov 21 at 6:15












  • can you check return value of bind and if it is less than zero use perror or check errno ?
    – Devidas
    Nov 21 at 6:30


















  • are you running this program as a root / privileged user ?
    – Devidas
    Nov 21 at 6:07










  • Yes,running as a root user.
    – avinash
    Nov 21 at 6:08










  • do you have auditd running ?
    – Devidas
    Nov 21 at 6:09










  • Yes. ps -eaf | grep -i auditd root 499 2 0 Nov16 ? 00:00:00 [kauditd] root 926 1 0 Nov16 ? 00:00:00 /sbin/auditd -n
    – avinash
    Nov 21 at 6:15












  • can you check return value of bind and if it is less than zero use perror or check errno ?
    – Devidas
    Nov 21 at 6:30
















are you running this program as a root / privileged user ?
– Devidas
Nov 21 at 6:07




are you running this program as a root / privileged user ?
– Devidas
Nov 21 at 6:07












Yes,running as a root user.
– avinash
Nov 21 at 6:08




Yes,running as a root user.
– avinash
Nov 21 at 6:08












do you have auditd running ?
– Devidas
Nov 21 at 6:09




do you have auditd running ?
– Devidas
Nov 21 at 6:09












Yes. ps -eaf | grep -i auditd root 499 2 0 Nov16 ? 00:00:00 [kauditd] root 926 1 0 Nov16 ? 00:00:00 /sbin/auditd -n
– avinash
Nov 21 at 6:15






Yes. ps -eaf | grep -i auditd root 499 2 0 Nov16 ? 00:00:00 [kauditd] root 926 1 0 Nov16 ? 00:00:00 /sbin/auditd -n
– avinash
Nov 21 at 6:15














can you check return value of bind and if it is less than zero use perror or check errno ?
– Devidas
Nov 21 at 6:30




can you check return value of bind and if it is less than zero use perror or check errno ?
– Devidas
Nov 21 at 6:30












1 Answer
1






active

oldest

votes

















up vote
0
down vote













try this flag



https://github.com/linux-audit/audit-userspace/blob/master/lib/libaudit.c#L383



from libaudit source code



rc = audit_get_reply(fd, &rep, GET_REPLY_NONBLOCKING,0);





share|improve this answer





















  • I have tried this as well before ,since it's non blocking call,it will come out without waiting there(used the polling as well before thi call) but not received any data
    – avinash
    Nov 22 at 1:23










  • Is there any other way as well to receive the iptable change notification ?
    – avinash
    Nov 22 at 1:25










  • maybe you have to configure audit with auditctl ? can you consult man page and try configuring it ?
    – Devidas
    Nov 22 at 8:12










  • from your observation it is clear that there is less probablity of this code having problem. as it may have given some error. so I feel is audit is not configured to listem to netlink related or for that matter any call by default. I suggest you to go through this access.redhat.com/documentation/en-us/red_hat_enterprise_linux/… specifically example 7.2 and try simmilar thing with given example try it works and then do same/ related for netlink
    – Devidas
    Nov 22 at 8:17










  • I tried configuring those setting earlier directly using auditctl command & can see the modifcation with "ausearch -k iptablesChange" command output..this time i configured more rules in /etc/audit/audit.rules file but still issue persist.
    – avinash
    Nov 23 at 8:43











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});






avinash is a new contributor. Be nice, and check out our Code of Conduct.










 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53405999%2fnetlink-notification-for-iptable-modification-are-not-received-to-application%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
0
down vote













try this flag



https://github.com/linux-audit/audit-userspace/blob/master/lib/libaudit.c#L383



from libaudit source code



rc = audit_get_reply(fd, &rep, GET_REPLY_NONBLOCKING,0);





share|improve this answer





















  • I have tried this as well before ,since it's non blocking call,it will come out without waiting there(used the polling as well before thi call) but not received any data
    – avinash
    Nov 22 at 1:23










  • Is there any other way as well to receive the iptable change notification ?
    – avinash
    Nov 22 at 1:25










  • maybe you have to configure audit with auditctl ? can you consult man page and try configuring it ?
    – Devidas
    Nov 22 at 8:12










  • from your observation it is clear that there is less probablity of this code having problem. as it may have given some error. so I feel is audit is not configured to listem to netlink related or for that matter any call by default. I suggest you to go through this access.redhat.com/documentation/en-us/red_hat_enterprise_linux/… specifically example 7.2 and try simmilar thing with given example try it works and then do same/ related for netlink
    – Devidas
    Nov 22 at 8:17










  • I tried configuring those setting earlier directly using auditctl command & can see the modifcation with "ausearch -k iptablesChange" command output..this time i configured more rules in /etc/audit/audit.rules file but still issue persist.
    – avinash
    Nov 23 at 8:43















up vote
0
down vote













try this flag



https://github.com/linux-audit/audit-userspace/blob/master/lib/libaudit.c#L383



from libaudit source code



rc = audit_get_reply(fd, &rep, GET_REPLY_NONBLOCKING,0);





share|improve this answer





















  • I have tried this as well before ,since it's non blocking call,it will come out without waiting there(used the polling as well before thi call) but not received any data
    – avinash
    Nov 22 at 1:23










  • Is there any other way as well to receive the iptable change notification ?
    – avinash
    Nov 22 at 1:25










  • maybe you have to configure audit with auditctl ? can you consult man page and try configuring it ?
    – Devidas
    Nov 22 at 8:12










  • from your observation it is clear that there is less probablity of this code having problem. as it may have given some error. so I feel is audit is not configured to listem to netlink related or for that matter any call by default. I suggest you to go through this access.redhat.com/documentation/en-us/red_hat_enterprise_linux/… specifically example 7.2 and try simmilar thing with given example try it works and then do same/ related for netlink
    – Devidas
    Nov 22 at 8:17










  • I tried configuring those setting earlier directly using auditctl command & can see the modifcation with "ausearch -k iptablesChange" command output..this time i configured more rules in /etc/audit/audit.rules file but still issue persist.
    – avinash
    Nov 23 at 8:43













up vote
0
down vote










up vote
0
down vote









try this flag



https://github.com/linux-audit/audit-userspace/blob/master/lib/libaudit.c#L383



from libaudit source code



rc = audit_get_reply(fd, &rep, GET_REPLY_NONBLOCKING,0);





share|improve this answer












try this flag



https://github.com/linux-audit/audit-userspace/blob/master/lib/libaudit.c#L383



from libaudit source code



rc = audit_get_reply(fd, &rep, GET_REPLY_NONBLOCKING,0);






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 21 at 9:43









Devidas

535212




535212












  • I have tried this as well before ,since it's non blocking call,it will come out without waiting there(used the polling as well before thi call) but not received any data
    – avinash
    Nov 22 at 1:23










  • Is there any other way as well to receive the iptable change notification ?
    – avinash
    Nov 22 at 1:25










  • maybe you have to configure audit with auditctl ? can you consult man page and try configuring it ?
    – Devidas
    Nov 22 at 8:12










  • from your observation it is clear that there is less probablity of this code having problem. as it may have given some error. so I feel is audit is not configured to listem to netlink related or for that matter any call by default. I suggest you to go through this access.redhat.com/documentation/en-us/red_hat_enterprise_linux/… specifically example 7.2 and try simmilar thing with given example try it works and then do same/ related for netlink
    – Devidas
    Nov 22 at 8:17










  • I tried configuring those setting earlier directly using auditctl command & can see the modifcation with "ausearch -k iptablesChange" command output..this time i configured more rules in /etc/audit/audit.rules file but still issue persist.
    – avinash
    Nov 23 at 8:43


















  • I have tried this as well before ,since it's non blocking call,it will come out without waiting there(used the polling as well before thi call) but not received any data
    – avinash
    Nov 22 at 1:23










  • Is there any other way as well to receive the iptable change notification ?
    – avinash
    Nov 22 at 1:25










  • maybe you have to configure audit with auditctl ? can you consult man page and try configuring it ?
    – Devidas
    Nov 22 at 8:12










  • from your observation it is clear that there is less probablity of this code having problem. as it may have given some error. so I feel is audit is not configured to listem to netlink related or for that matter any call by default. I suggest you to go through this access.redhat.com/documentation/en-us/red_hat_enterprise_linux/… specifically example 7.2 and try simmilar thing with given example try it works and then do same/ related for netlink
    – Devidas
    Nov 22 at 8:17










  • I tried configuring those setting earlier directly using auditctl command & can see the modifcation with "ausearch -k iptablesChange" command output..this time i configured more rules in /etc/audit/audit.rules file but still issue persist.
    – avinash
    Nov 23 at 8:43
















I have tried this as well before ,since it's non blocking call,it will come out without waiting there(used the polling as well before thi call) but not received any data
– avinash
Nov 22 at 1:23




I have tried this as well before ,since it's non blocking call,it will come out without waiting there(used the polling as well before thi call) but not received any data
– avinash
Nov 22 at 1:23












Is there any other way as well to receive the iptable change notification ?
– avinash
Nov 22 at 1:25




Is there any other way as well to receive the iptable change notification ?
– avinash
Nov 22 at 1:25












maybe you have to configure audit with auditctl ? can you consult man page and try configuring it ?
– Devidas
Nov 22 at 8:12




maybe you have to configure audit with auditctl ? can you consult man page and try configuring it ?
– Devidas
Nov 22 at 8:12












from your observation it is clear that there is less probablity of this code having problem. as it may have given some error. so I feel is audit is not configured to listem to netlink related or for that matter any call by default. I suggest you to go through this access.redhat.com/documentation/en-us/red_hat_enterprise_linux/… specifically example 7.2 and try simmilar thing with given example try it works and then do same/ related for netlink
– Devidas
Nov 22 at 8:17




from your observation it is clear that there is less probablity of this code having problem. as it may have given some error. so I feel is audit is not configured to listem to netlink related or for that matter any call by default. I suggest you to go through this access.redhat.com/documentation/en-us/red_hat_enterprise_linux/… specifically example 7.2 and try simmilar thing with given example try it works and then do same/ related for netlink
– Devidas
Nov 22 at 8:17












I tried configuring those setting earlier directly using auditctl command & can see the modifcation with "ausearch -k iptablesChange" command output..this time i configured more rules in /etc/audit/audit.rules file but still issue persist.
– avinash
Nov 23 at 8:43




I tried configuring those setting earlier directly using auditctl command & can see the modifcation with "ausearch -k iptablesChange" command output..this time i configured more rules in /etc/audit/audit.rules file but still issue persist.
– avinash
Nov 23 at 8:43










avinash is a new contributor. Be nice, and check out our Code of Conduct.










 

draft saved


draft discarded


















avinash is a new contributor. Be nice, and check out our Code of Conduct.













avinash is a new contributor. Be nice, and check out our Code of Conduct.












avinash is a new contributor. Be nice, and check out our Code of Conduct.















 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53405999%2fnetlink-notification-for-iptable-modification-are-not-received-to-application%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Berounka

Sphinx de Gizeh

Different font size/position of beamer's navigation symbols template's content depending on regular/plain...