2011-04-04 25 views
5

Tôi đã biên soạn Linux cho trình giả lập Android với chức năng netfilter đầy đủ được bật. Và có một nhị phân iptables sau khi xây dựng android từ nguồn.lỗi iptables trong android: iptables-save và iptables-restore không hoạt động

Khi tôi đẩy nhị phân này vào trình mô phỏng

tôi có thể thực hiện các lệnh như dưới đây thành công.

iptables -L 
iptables -F 
iptables -A INPUT -s www.google.com -j DROP 

với lỗi này:

# # iptables -L 
getsockopt for multiport failed strangely: No such file or directory 
getsockopt for multiport failed strangely: No such file or directory 
Chain INPUT (policy ACCEPT) 
target  prot opt source    destination   

Chain FORWARD (policy ACCEPT) 
target  prot opt source    destination   

Chain OUTPUT (policy ACCEPT) 
target  prot opt source    destination   
# 

# iptables -A INPUT -s www.google.com -j DROP 
getsockopt for multiport failed strangely: No such file or directory 
getsockopt for multiport failed strangely: No such file or directory 
FIX ME! implement getgrnam() bionic/libc/bionic/stubs.c:344 

nhưng ít nhất các lệnh trên họ làm việc!

nhưng khi tôi cố gắng

iptables-save  or 
iptables-restore 

tôi nhận lỗi nói

iptables-save: not found 

Trong tập tin cấu hình của tôi

CONFIG_NETFILTER_XT_MATCH_MULTIPORT=m 

vấn đề là gì .. ?? và làm thế nào tôi có thể kích hoạt chức năng iptables đầy đủ trong Android hoặc làm thế nào tôi có thể lưu các quy tắc iptables hoạt động hiện tại một cách an toàn và tải lại chúng khi khởi động lại tiếp theo.

vui lòng trợ giúp. cảm ơn bạn!

+0

Tôi khá chắc chắn 'iptables-save' và' iptables-restore' là mã nhị phân khác nhau, do vậy tại sao họ không chứa khoảng trắng (như trái ngược với 'iptables -L', ví dụ, mà làm) . – eldarerathis

+0

thực sự tôi muốn viết iptables-save hoặc iptables-retore như một câu. lấy làm tiếc. – Preetam

Trả lời

1

Đây là những gì tôi đã thêm vào Android.mk tôi để có được cả hai iptables-save và iptables-retore. Nó biên dịch ok trên Android 4.0.3.

 


#---------------------------------------------------------------- 
# iptables-save 


include $(CLEAR_VARS) 

LOCAL_C_INCLUDES:= \ 
    $(LOCAL_PATH)/../include/ 

LOCAL_CFLAGS:=-DNO_SHARED_LIBS=1 
LOCAL_CFLAGS+=-DALL_INCLUSIVE 
LOCAL_CFLAGS+=-DXTABLES_INTERNAL 
# Accommodate arm-eabi-4.4.3 tools that don't set __ANDROID__ 
LOCAL_CFLAGS+=-D__ANDROID__ 

LOCAL_SRC_FILES:= \ 
    iptables-save.c iptables.c xshared.c 

LOCAL_MODULE_TAGS := optional 
LOCAL_MODULE:=iptables-save 

LOCAL_STATIC_LIBRARIES := \ 
    libext \ 
    libext4 \ 
    libip4tc \ 
    libxtables 

include $(BUILD_EXECUTABLE) 


#---------------------------------------------------------------- 
# iptables-restore 


include $(CLEAR_VARS) 

LOCAL_C_INCLUDES:= \ 
    $(LOCAL_PATH)/../include/ 

LOCAL_CFLAGS:=-DNO_SHARED_LIBS=1 
LOCAL_CFLAGS+=-DALL_INCLUSIVE 
LOCAL_CFLAGS+=-DXTABLES_INTERNAL 
# Accommodate arm-eabi-4.4.3 tools that don't set __ANDROID__ 
LOCAL_CFLAGS+=-D__ANDROID__ 

LOCAL_SRC_FILES:= \ 
    iptables-restore.c iptables.c xshared.c 

LOCAL_MODULE_TAGS := optional 
LOCAL_MODULE:=iptables-restore 

LOCAL_STATIC_LIBRARIES := \ 
    libext \ 
    libext4 \ 
    libip4tc \ 
    libxtables 

include $(BUILD_EXECUTABLE) 

2

iptables-saveiptables-restore mã nhị phân không được tạo bởi các tệp makefiles hệ thống Android mặc định.

Bạn cần phải thêm quy tắc vào tệp Android.mk trong $mydroid/external/iptables/ để tạo chúng. Các tệp nguồn, iptables-save.ciptables-restore.c đã có trong thư mục đó.

Chưa được kiểm tra, nhưng để tạo iptables-save, hãy thêm thông tin như thế này vào cuối Android.mk. Rửa sạch và lặp lại cho iptables-restore:

# 
# Build iptables-save 
# 

include $(CLEAR_VARS) 

LOCAL_C_INCLUDES:= \ 
    $(LOCAL_PATH)/include/ \ 
    $(KERNEL_HEADERS) 

LOCAL_CFLAGS:=-DNO_SHARED_LIBS 
LOCAL_CFLAGS+=-DIPTABLES_VERSION=\"1.3.7\" 

LOCAL_SRC_FILES:= \ 
    iptables-save.c 

LOCAL_MODULE_TAGS:=debug 
LOCAL_MODULE:=iptables-save 

LOCAL_STATIC_LIBRARIES := \ 
    libiptc \ 
    libext 

include $(BUILD_EXECUTABLE) 
+0

Cảm ơn bạn rất nhiều David! nhưng khi tôi làm điều này tôi nhận được nhiều lỗi như: – Preetam

+0

xin lỗi, tôi đã không thể nhập đầu ra trong các ý kiến, vì vậy tôi đặt nó trong câu trả lời. – Preetam

+0

nếu nhóm Android đã sửa đổi nguồn iptables, để loại trừ iptables-lưu hơn là họ phải sửa đổi một số tệp nguồn có chức năng gọi trong iptables-save (tôi nghĩ). Có thể vì lý do đó, lỗi xảy ra. – Preetam

Các vấn đề liên quan