2014/02/06

修正 sourceforge 裡面 igmpproxy 在 pppx 連線下 (例如 pppoe) 無法運作的問題

igmpproxy 透過 config 檔設定 interface 是 upstream 或是 downstream,然後由 ifvc.c 裡面的 buildIfVc() 來建立各 interface 的資訊。buildIfVc() 建立資訊的方式是去蒐集各 interface 的 ip 資訊,然而 p-t-p 的 ip 資訊會拿到近端 ip/32,導致無法成功運行 igmpproxy 該做的事情。所以需要更改程式,讓他取得遠端的 ip 而不是近端的 ip 才能正常運作。

需增加的程式如下(紅色部份):
            if ( ioctl( Sock, SIOCGIFFLAGS, &IfReq ) < 0 )
                my_log( LOG_ERR, errno, "ioctl SIOCGIFFLAGS" );

            IfDescEp->Flags = IfReq.ifr_flags;

            // aimwang: when pppx get dstaddr for use
            if (0x10d1 == IfDescEp->Flags)    // when pppx
            {
                if ( ioctl( Sock, SIOCGIFDSTADDR, &IfReq ) < 0 )    // get dstaddr
                    my_log(LOG_ERR, errno, "ioctl SIOCGIFDSTADDR for %s", IfReq.ifr_name);
                addr = ((struct sockaddr_in *)&IfReq.ifr_dstaddr)->sin_addr.s_addr;    // rewrite addr
                subnet = addr & mask;    // recalc subnet
            }

            // Insert the verified subnet as an allowed net...
            IfDescEp->allowednets = (struct SubnetList *)malloc(sizeof(struct SubnetList));
            if(IfDescEp->allowednets == NULL) my_log(LOG_ERR, 0, "Out of memory !");

這樣就能取得遠端 ip 來進行 igmpproxy 該有的行為