Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iptc has problem when working with syslog module. #321

Open
crazyyao0 opened this issue May 19, 2021 · 0 comments
Open

iptc has problem when working with syslog module. #321

crazyyao0 opened this issue May 19, 2021 · 0 comments

Comments

@crazyyao0
Copy link

Not sure why iptc cannot work with syslog module. For the following code, test1 will only send the first 2 log messages. test2 and test3 works properly. I tested this on different linuxs and different python versions.

import syslog
import iptc # pip install python-iptables
import os
import socket

def log(msg):
    syslog.openlog(ident="xxxxxx")
    syslog.syslog(syslog.LOG_INFO, msg)
    syslog.closelog()

def log2(msg):
    sock = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM|socket.SOCK_CLOEXEC)
    sock.connect("/dev/log")
    sock.send(("  xxxxxx: "+msg).encode("utf-8"))
    sock.close()

def add_rule_cmdline():
    os.system("iptables -A INPUT -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT")

def add_rule_iptc():
    table = iptc.Table(iptc.Table.FILTER)
    chain = iptc.Chain(table, "INPUT")
    rule1 = {'target': 'ACCEPT','conntrack': {'ctstate': 'RELATED,ESTABLISHED'}}
    chain.append_rule(iptc.easy.encode_iptc_rule(rule1))
    table.close()

#no test2 received
def test1():  
    log("test0")
    os.system("iptables -F")
    log("test1")
    add_rule_iptc()
    log("test2")

#working
def test2():  
    log("test0")
    os.system("iptables -F")
    log("test1")
    add_rule_cmdline()
    log("test2")

#working
def test3():  
    log2("test0")
    os.system("iptables -F")
    log2("test1")
    add_rule_iptc()
    log2("test2")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant