9f0c05095867cbb9197550f29582bab83e69f9e5
[project/netifd.git] / dummy / proto / ppp.sh
1 #!/bin/sh
2
3 . ../netifd-proto.sh
4 init_proto "$@"
5
6 ppp_generic_init_config() {
7         proto_config_add_string "username"
8         proto_config_add_string "password"
9         proto_config_add_int "keepalive"
10 }
11
12 proto_ppp_init_config() {
13         no_device=1
14         available=1
15         ppp_generic_init_config
16 }
17
18 proto_ppp_setup() {
19         echo "ppp_setup($1): $2"
20 }
21
22 proto_ppp_teardown() {
23         return
24 }
25
26 add_protocol ppp
27
28 proto_pppoe_init_config() {
29         ppp_generic_init_config
30 }
31
32 proto_pppoe_setup() {
33         local interface="$1"
34         local device="$2"
35
36         json_get_var username username
37         json_get_var password password
38         echo "pppoe_setup($interface, $device), username=$username, password=$password"
39         proto_init_update ppp0 1
40         proto_add_ipv4_address "192.168.2.1" 32
41         proto_add_dns_server "192.168.2.2"
42         proto_add_ipv4_route "0.0.0.0" 0 192.168.2.2
43         proto_add_data
44         json_add_string "ppp-type" "pppoe"
45         proto_close_data
46         proto_send_update "$interface"
47         proto_run_command "$interface" sleep 30
48 }
49
50 proto_pppoe_teardown() {
51         [ "$ERROR" = 9 ] && {
52                 proto_notify_error "$interface" PROCESS_KILLED
53                 proto_block_restart "$interface"
54         }
55         proto_kill_command "$interface"
56         return
57 }
58
59 add_protocol pppoe