Страница 1 из 1

[netgraph] ng_patch

Добавлено: 2012-05-18 17:34:16
ivasian
Пытался использовать ng_patch, прочитал ман, пару статей по этой ноде сделал такой конфиг:

Код: Выделить всё

#!/bin/sh

case $1 in
start)
        echo "Starting ng_nat..."
        ngctl mkpeer ipfw: patch 1 in
        ngctl name ipfw:1 ptch
        ngctl connect ipfw: ptch: 2 out
        ngctl msg ptch: setconfig { count=8 csum_flags=1 ops [ \
                                {mode=7 value=0x00 length=1 offset=16} \
                                {mode=7 value=0x00 length=1 offset=17} \
                                {mode=7 value=0x00 length=1 offset=18} \
                                {mode=7 value=0x00 length=1 offset=19} \
                                {mode=8 value=0x01 length=1 offset=16} \
                                {mode=8 value=0x01 length=1 offset=17} \
                                {mode=8 value=0x01 length=1 offset=18} \
                                {mode=8 value=0x01 length=1 offset=19}]}
        echo "Done..."

        echo "ipfw rules..."

        ipfw="/sbin/ipfw -q"
        ${ipfw} flush -f
        ${ipfw} add 1000 skipto 2000 ip from any to any in recv em0
        ${ipfw} add 1001 skipto 5000 ip from any to any out xmit em0
        ${ipfw} add 1006 skipto 8000 ip from any to any in recv em1
        ${ipfw} add 1007 skipto 9000 ip from any to any out xmit em1

        #################### em0 in #######################
        ${ipfw} add 3000 netgraph 2 ip from any to any
        ${ipfw} add 4999 allow ip from any to any
        #################### em0 out #######################
        ${ipfw} add 6000 netgraph 1 ip from any to any
        ${ipfw} add 7999 allow ip from any to any
        #################### em1 in #######################
        #################### em1 out ######################
        ${ipfw} add 65000 allow ip from any to any

        echo "ipfw rules applied"
        exit 0
;;
Ожидаю от него следующего, в пакетах которые попадают на out em0 меняется адрес источника на 1.1.1.1. Но ничего не происходит,

Код: Выделить всё

tcpdump -i em0 icmp 
Показывает что пакеты не изменяются, что только не делал - результата - два или пакеты не меняются, или пакеты пропадают ( в других конфигах). Если у кого то есть любой РАБОЧИЙ пример использования ng_patch - милости прошу.

Re: [netgraph] ng_patch

Добавлено: 2012-05-19 7:56:27
ivasian
Разбор проблемы продолжился в комментариях
http://nuclight.livejournal.com/126002. ... 2&#t844082

Re: [netgraph] ng_patch

Добавлено: 2012-05-21 11:44:32
ivasian
Итоговый рабочий вариант скрипта который меняет scr ip на 1.1.1.1

Код: Выделить всё

#!/bin/sh

case $1 in
start)
        echo "Starting izvrat..."
        ngctl mkpeer ipfw: patch 1 in
        ngctl name ipfw:1 ptch
        ngctl connect ipfw: ptch: 2 out
        ngctl msg ptch: setconfig { count=1 csum_flags=1 ops=[{mode=1 value=0x01010101 length=4 offset=12}]}
        echo "Done..."

        echo "ipfw rules..."

        ipfw="/sbin/ipfw -q"
        ${ipfw} flush -f
        ${ipfw} add 1000 skipto 2000 ip from any to any in recv em0
        ${ipfw} add 1001 skipto 5000 ip from any to any out xmit em0
        ${ipfw} add 1006 skipto 8000 ip from any to any in recv em1
        ${ipfw} add 1007 skipto 9000 ip from any to any out xmit em1

        #################### em0 in #######################
        ${ipfw} add 4999 allow ip from any to any
        #################### em0 out #######################
        ${ipfw} add 6000 netgraph 1 ip from any to any
        ${ipfw} add 7999 allow ip from any to any
        #################### em1 in #######################
        #################### em1 out ######################
        ${ipfw} add 65000 allow ip from any to any

        echo "ipfw rules applied"
        exit 0
;;
Не забываем про это:
http://svnweb.freebsd.org/base/head/sys ... &r2=234574