I use python socket module to simulate a pppoe server, but how to generate the ppp0 interface?

222 Views Asked by At

I use python socket module to simulate a pppoe server, the server can receive ppp connection packet from client such as PADI/PADR/LCP Request... , however after the connection finished,there is no ppp0 interface on sever. I wish the ppp0 interface can be up automatically after the ppp connection finished ,please help...

import socket

def main():
    server_socket = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, socket.ntohs(0x8863))

    interface ='eth0'

    server_socket.bind((interface, 0))

    while True:
        try:
            data, addr = server_socket.recvfrom(4096)
            '''
            handle pppoe packets here and finish the pppoe connection
            '''

        except KeyboardInterrupt:
            break

    server_socket.close()

if __name__ == "__main__":
    main()

My OS is ubuntu 18.04..

I expect that after the ppp connection between client and server finished, there should be a ppp0 interface on my server.

For example server IP is 20.20.20.1 and the client get IP 20.20.20.2 ,I wish the interface on server should be like:

ppp0: flags=4305<UP,POINTOPOINT,RUNNING,NOARP,MULTICAST>  mtu 1492
        inet 20.20.20.1  netmask 255.255.255.255  destination 20.20.20.2
        ppp  txqueuelen 3  (Point-to-Point Protocol)
        RX packets 194  bytes 14365 (14.3 KB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 175  bytes 13081 (13.0 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0


Anyone have some ideas? Thanks...

1

There are 1 best solutions below

5
Hamed On

The OS handle Virtual interfaces.

According to OS you are using, you should read manuals about it.

For example in linux you can use networkd or ip command to make a new virtual interface.

You can use these commands:

ip link add name MYNEWINTERFACE type dummy
ifconfig MYNEWINTERFACE up

Check other options with:

man ip-link