policy_module(l2tp, 1.1.0)

########################################
#
# Declarations
#

type l2tpd_t;
type l2tpd_exec_t;
init_daemon_domain(l2tpd_t, l2tpd_exec_t)

type l2tpd_initrc_exec_t;
init_script_file(l2tpd_initrc_exec_t)

type l2tp_conf_t;
files_config_file(l2tp_conf_t)

type l2tpd_tmp_t;
files_tmp_file(l2tpd_tmp_t)

type l2tpd_var_run_t;
files_pid_file(l2tpd_var_run_t)

########################################
#
# Local policy
#

allow l2tpd_t self:capability net_admin;
allow l2tpd_t self:process signal_perms;
allow l2tpd_t self:fifo_file rw_fifo_file_perms;
allow l2tpd_t self:netlink_socket create_socket_perms;
allow l2tpd_t self:rawip_socket create_socket_perms;
allow l2tpd_t self:socket create_socket_perms;
allow l2tpd_t self:tcp_socket { accept listen };
allow l2tpd_t self:unix_dgram_socket sendto;
allow l2tpd_t self:unix_stream_socket { accept listen };
allow l2tpd_t self:pppox_socket create_socket_perms;

read_files_pattern(l2tpd_t, l2tp_conf_t, l2tp_conf_t)

manage_dirs_pattern(l2tpd_t, l2tpd_var_run_t, l2tpd_var_run_t)
manage_files_pattern(l2tpd_t, l2tpd_var_run_t, l2tpd_var_run_t)
manage_sock_files_pattern(l2tpd_t, l2tpd_var_run_t, l2tpd_var_run_t)
manage_fifo_files_pattern(l2tpd_t, l2tpd_var_run_t, l2tpd_var_run_t)
files_pid_filetrans(l2tpd_t, l2tpd_var_run_t, { dir file sock_file fifo_file })

manage_sock_files_pattern(l2tpd_t, l2tpd_tmp_t, l2tpd_tmp_t)
files_tmp_filetrans(l2tpd_t, l2tpd_tmp_t, sock_file)

can_exec(l2tpd_t, l2tpd_exec_t)

corenet_all_recvfrom_unlabeled(l2tpd_t)
corenet_all_recvfrom_netlabel(l2tpd_t)
corenet_raw_sendrecv_generic_if(l2tpd_t)
corenet_tcp_sendrecv_generic_if(l2tpd_t)
corenet_udp_sendrecv_generic_if(l2tpd_t)
corenet_raw_bind_generic_node(l2tpd_t)
corenet_tcp_bind_generic_node(l2tpd_t)
corenet_udp_bind_generic_node(l2tpd_t)
corenet_raw_sendrecv_generic_node(l2tpd_t)
corenet_tcp_sendrecv_generic_node(l2tpd_t)
corenet_udp_sendrecv_generic_node(l2tpd_t)
corenet_tcp_sendrecv_all_ports(l2tpd_t)
corenet_udp_sendrecv_all_ports(l2tpd_t)

corenet_sendrecv_all_server_packets(l2tpd_t)
corenet_tcp_bind_all_rpc_ports(l2tpd_t)
corenet_udp_bind_all_rpc_ports(l2tpd_t)

corenet_udp_bind_l2tp_port(l2tpd_t)

kernel_read_network_state(l2tpd_t)
kernel_read_system_state(l2tpd_t)
kernel_request_load_module(l2tpd_t)

corecmd_exec_bin(l2tpd_t)

dev_read_urand(l2tpd_t)

term_setattr_generic_ptys(l2tpd_t)
term_use_generic_ptys(l2tpd_t)
term_use_ptmx(l2tpd_t)

auth_read_passwd(l2tpd_t)
auth_map_passwd(l2tpd_t)

logging_send_syslog_msg(l2tpd_t)

sysnet_dns_name_resolve(l2tpd_t)

optional_policy(`
    dbus_system_bus_client(l2tpd_t)
    dbus_connect_system_bus(l2tpd_t)
    
    optional_policy(`
        networkmanager_dbus_chat(l2tpd_t)
    ')
')

optional_policy(`
    ipsec_domtrans_mgmt(l2tpd_t)
    ipsec_mgmt_read_pid(l2tpd_t)
    ipsec_filetrans_key_file(l2tpd_t)
    ipsec_manage_key_file(l2tpd_t)
    ipsec_kill_mgmt(l2tpd_t)
    ipsec_read_config(l2tpd_t)
    ipsec_signull_mgmt(l2tpd_t)
')

optional_policy(`
    sssd_run_stream_connect(l2tpd_t)
    sssd_stream_connect(l2tpd_t)
    sssd_read_public_files(l2tpd_t)
')

optional_policy(`
	networkmanager_manage_pid_files(l2tpd_t)
')

optional_policy(`
	ppp_domtrans(l2tpd_t)
	ppp_signal(l2tpd_t)
	ppp_kill(l2tpd_t)
')
