Code Monkey home page Code Monkey logo

improxy's Introduction

IMProxy

IMProxy is an IGMP/MLD Proxy daemon written in c for Linux router.

Features:

  • Very lightweight and do not depend on any thirdparty library.
  • Supports source filtering completely.
  • Implement IGMP/MLD proxy standard (RFC 4605) IGMPv3(rfc 3376) MLDv2(rfc 3810).
  • Supports one upstream interface and multiple downstream interfaces.
  • Supports group quick leave

It support one upstream and multiple downstream.

How to Test

You can use VLC Player, or other mcast test tools. I will show you have to test with mcast_test.py in this repository. On downstream side PC, run mulitcast recevier.

mcast_test.py -m 224.8.8.8 -r ## Join 224.8.8.8 and start receive packets 

On upstream side PC, run mulitcast sender

mcast_test.py -m 224.8.8.8 -s ## send packet to 224.8.8.8 

Check if Recevier start to print time.

How to Debug

Take sample.cfg as sample and run test above.

IMProxy create Virtual Network Devices when it start, every interface have a unique index,you can find this through 'cat /proc/net/ip_mr_vif

/var # cat /proc/net/ip_mr_vif
Interface      BytesIn  PktsIn  BytesOut PktsOut Flags Local    Remote
15 wan1          15804      50         0       0 00000 C0A8164C 00000000
24 eth0.1            0       0     15804      50 00000 C0A81501 00000000
26 eth0.3            0       0         0       0 00000 C0A81301 00000000
27 eth0.4            0       0         0       0 00000 C0A81401 00000000
28 eth0.5            0       0      9264      24 00000 C0A81B01 00000000

When IMProxy receive igmp report on downstream interface(eth0.1), improxy will parse it and join related group on upstream interface(wan1) cat /proc/net/igmp

/var # cat /proc/net/igmp
Idx     Device    : Count Querier       Group    Users Timer    Reporter
...................
15      wan1      :     9      V3
                                E0080808     1 0:00000000               0
                                E00000FB     1 0:00000000               0
                                E00000FC     1 0:00000000               0
                                E0000009     1 0:00000000               0
                                EFFFFFFA     1 0:00000000               0
                                E0000002     1 0:00000000               0
                                E0000016     1 0:00000000               0
                                E0000001     1 0:00000000               0
24      eth0.1    :     7      V3
                                E0000009     1 0:00000000               0
                                E0000016     1 0:00000000               0
                                E0000002     1 0:00000000               0
                                EFFFFFFA     1 0:00000000               0
                                E0000001     1 0:00000000               0
.........................
                                

When mulitcast data arrive at upstream interface(wan1), linux kernel send a packet to improxy, this packet contain source address,group address and interface, according to these information,IMProxy will create a Multicast Forwarding Cache,you can find this through cat /proc/net/ip_mr_cache

/var # cat /proc/net/ip_mr_cache
Group    Origin   Iif     Pkts    Bytes    Wrong Oifs
E0080808 C0A80799 15         8     8480        0 24:1           /*froward data from 15(wan1) to 24(eth0.1) */
EFFFFFFA C0A80799 15       100    31608        0 24:1   28:1
EFFFFFFA C0A80199 65535 -2073669404        4 -2073669404
EFFFFFFA C0A81501 65535 -2073667868        4 -2073667868

Kernel forward multicast data on the basis of multicast forwarding cache.

improxy's People

Contributors

haibbo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

improxy's Issues

enhncments suggestions

Hello and thank you for this igmp/mld proxy code
I run some static code analysis on it and I would like to share somes results with you

  1. input.c mcast_recv_igmp() => unreachable code : else if (ip->protocol == 0)
  2. proxy.c main() => unreachable code : free_resource();
    I think the proxy need to handle system signal in order to cleanup ressources
  3. output.c send_igmp_mld_query() => unreachable code : if(p_if == NULL) (line 84)
  4. proxy.c load_config() => resource lost : need to close fd
  5. output.c send_igmp_mld_query() => possible memory leak : p = malloc(max_len)
    if family is neither AF_INET nor AF_INET6

I hope it help
Best Reagrds

access to a memory that has been free

Dear author:
I would like to report a problem (bug).

at source_timer_handler() in data.c, the code segment could have crash risk.

The imp_group_cleanup(p_gp) will free (p_gp) at end of that function.
After return, the last line "imp_membership_db_update(&p_gp->group_addr);"

reference it again. But p_gp is freed. So, that could have problem with some compiler or system..

if(p_gp->type == GROUP_INCLUDE && imp_source_exist_allow(p_gp) == 0){

    /* If there are no more source records for the group, delete group record.
     * rfc 3376 [6.3]
     */
    imp_group_cleanup(p_gp);
}
imp_membership_db_update(&p_gp->group_addr);

imp_get_mfcc_ttls() and iface index

Function imp_get_mfcc_ttls() checks that

p_if->if_index < length

where length is MAXVIFS (32 for linux).

But interface index may be greater than this value.
SOHO routers may have 40 interfaces (e.g. Realtek-based routers with real and virtual wifi interfaces, wds etc). As a result, eth1 (wan) and br0 (lan) have indexes greater than 32 and improxy doesn't call
imp_membership_db_mfc_add() because imp_get_mfcc_ttls returns 0.

I don't quite understand this limitation. I removed it for my device. But as a generic solution, maybe you should check the number of interfaces for which you call k_add_ip6_mif or k_add_ip4_vif.

IPv4 Multicast Address is judged non-multciast-address

First of all, thanks you a lot for this package.
It does help me solve the problem. The only one workable for IGMP/MLD proxy I can find.
Thank You.

I try this software on a ARM little endian and got some warning message as title.
I fix it and attach the changes. Hope this help someone.

input.c, the "ntohl" part is not existed in original code. I add this to fix the problem.

} else if(p_pia->ss.ss_family == AF_INET) {

    if (!IN_MULTICAST(ntohl(p_pia->v4.sin_addr.s_addr))) {
        IMP_LOG_ERROR("group address %s isn't multicast adddress\n",
                      imp_pi_ntoa(p_pia));
        return -1;
    }

    /*
     *    Address Range                 Size       Designation
     *    -------------                 ----       -----------
     *    224.0.0.0 - 224.0.0.255       (/24)      Local Network Control Block
     *
     *    Addresses in the Local Network Control Block are used for protocol
     *    control traffic that is not forwarded off link.
     *    [RFC 5771 section 4]
     */

ERROR[init_mproxy4@332]: can't create igmp socket

Hi,
I need to forward IGMPv3 messages from enp0s8 to enp0s9, my .conf is this:

igmp enable version 3
mld enable
upstream enp0s8
downstream enp0s9

But I get the following error:

DEBUG[main@580]: logLevel = 5
DEBUG[load_config@76]: buffer = igmp enable version 3
DEBUG[load_config@94]: token is igmp
DEBUG[load_config@76]: buffer = mld enable
DEBUG[load_config@94]: token is mld
DEBUG[load_config@76]: buffer = upstream enp0s8
DEBUG[load_config@94]: token is upstream
DEBUG[load_config@185]: upstream interface is enp0s8
DEBUG[load_config@76]: buffer = downstream enp0s9
DEBUG[load_config@94]: token is downstream
DEBUG[load_config@194]: downstream interface is enp0s9
DEBUG[init_interface@189]: enp0s9's ipv6 address is fe80::a00:27ff:feff:4040
DEBUG[init_interface@195]: if_index = 4
DEBUG[init_interface@208]: if_mtu = 1500
DEBUG[init_interface@214]: if_falgs = 4163
DEBUG[init_interface@189]: enp0s8's ipv6 address is fe80::a00:27ff:fe89:fa25
DEBUG[init_interface@195]: if_index = 3
DEBUG[init_interface@208]: if_mtu = 1500
DEBUG[init_interface@214]: if_falgs = 4163
DEBUG[init_interface@178]: enp0s9's ipv4 address is 192.168.2.2
DEBUG[init_interface@195]: if_index = 4
DEBUG[init_interface@208]: if_mtu = 1500
DEBUG[init_interface@214]: if_falgs = 4163
DEBUG[init_interface@178]: enp0s8's ipv4 address is 192.168.1.1
DEBUG[init_interface@195]: if_index = 3
DEBUG[init_interface@208]: if_mtu = 1500
DEBUG[init_interface@214]: if_falgs = 4163
ERROR[init_mproxy4@332]: can't create igmp socket
ERROR[main@619]: exiting.........

Do you have an idea why igmp socket can be created?

Running on Ubuntu VM:

description: Computer
width: 64 bits
capabilities: vsyscall32
*-core
description: Motherboard
physical id: 0
*-memory
description: System memory
physical id: 0
size: 16GiB
*-cpu
product: Intel(R) Core(TM) i7-10850H CPU @ 2.70GHz
vendor: Intel Corp.
physical id: 1
bus info: cpu@0
width: 64 bits

Thanks

commit 4a7f5e2c4c1 breaks improxy

I have some troubles with this commit.

I tested improxy five months ago and reverted this commit because I don't need to forward packets from one downstream to other interfaces. After that my router started to forward IPv6 multicast from wan to lan correctly.

I decided to check it again.
In this commit you disabled k_mcast_msfilter.
As a result, Linux Kernel sends MLD2 reports (leaves) with incorect record type.
Attachment contains additional information:

2018-07-02 13:06:00.058 INFO(wan): Expecting MLDv2 record type CHANGE_TO_INCLUDE_MODE for group ff0e::1, but found CHANGE_TO_EXCLUDE_MODE

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.