policy_module(openvswitch, 1.1.1)

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

type openvswitch_t;
type openvswitch_exec_t;
init_daemon_domain(openvswitch_t, openvswitch_exec_t)

type openvswitch_rw_t;
files_config_file(openvswitch_rw_t)

type openvswitch_var_lib_t;
files_type(openvswitch_var_lib_t)

type openvswitch_log_t;
logging_log_file(openvswitch_log_t)

type openvswitch_tmp_t;
files_tmp_file(openvswitch_tmp_t)

type openvswitch_var_run_t;
files_pid_file(openvswitch_var_run_t)

type openvswitch_unit_file_t;
systemd_unit_file(openvswitch_unit_file_t)

########################################
#
# openvswitch local policy
#

allow openvswitch_t self:capability { dac_override dac_read_search fowner net_broadcast net_admin ipc_lock sys_module sys_nice sys_rawio sys_resource chown setgid setpcap setuid kill };
allow openvswitch_t self:capability2 block_suspend;
allow openvswitch_t self:process { fork setsched setrlimit signal setcap };
allow openvswitch_t self:fifo_file rw_fifo_file_perms;
allow openvswitch_t self:unix_stream_socket { create_stream_socket_perms connectto };
allow openvswitch_t self:tcp_socket create_stream_socket_perms;
allow openvswitch_t self:netlink_socket create_socket_perms;
allow openvswitch_t self:netlink_route_socket rw_netlink_socket_perms;
allow openvswitch_t self:netlink_generic_socket create_socket_perms;
allow openvswitch_t self:netlink_netfilter_socket create_socket_perms;
allow openvswitch_t self:netlink_xfrm_socket create_netlink_socket_perms;
allow openvswitch_t self:tun_socket { create_socket_perms relabelfrom relabelto };
allow openvswitch_t self:system { module_load };

can_exec(openvswitch_t, openvswitch_exec_t)

manage_dirs_pattern(openvswitch_t, openvswitch_rw_t, openvswitch_rw_t)
manage_files_pattern(openvswitch_t, openvswitch_rw_t, openvswitch_rw_t)
manage_lnk_files_pattern(openvswitch_t, openvswitch_rw_t, openvswitch_rw_t)

manage_dirs_pattern(openvswitch_t, openvswitch_var_lib_t, openvswitch_var_lib_t)
manage_files_pattern(openvswitch_t, openvswitch_var_lib_t, openvswitch_var_lib_t)
manage_lnk_files_pattern(openvswitch_t, openvswitch_var_lib_t, openvswitch_var_lib_t)
files_var_lib_filetrans(openvswitch_t, openvswitch_var_lib_t, { dir file lnk_file })

manage_dirs_pattern(openvswitch_t, openvswitch_log_t, openvswitch_log_t)
manage_files_pattern(openvswitch_t, openvswitch_log_t, openvswitch_log_t)
manage_lnk_files_pattern(openvswitch_t, openvswitch_log_t, openvswitch_log_t)
logging_log_filetrans(openvswitch_t, openvswitch_log_t, { dir file lnk_file })

manage_dirs_pattern(openvswitch_t, openvswitch_tmp_t, openvswitch_tmp_t)
manage_files_pattern(openvswitch_t, openvswitch_tmp_t, openvswitch_tmp_t)
manage_lnk_files_pattern(openvswitch_t, openvswitch_tmp_t, openvswitch_tmp_t)
manage_sock_files_pattern(openvswitch_t, openvswitch_tmp_t, openvswitch_tmp_t)
files_tmp_filetrans(openvswitch_t, openvswitch_tmp_t, { file dir sock_file })

manage_dirs_pattern(openvswitch_t, openvswitch_var_run_t, openvswitch_var_run_t)
manage_files_pattern(openvswitch_t, openvswitch_var_run_t, openvswitch_var_run_t)
manage_sock_files_pattern(openvswitch_t, openvswitch_var_run_t, openvswitch_var_run_t)
manage_lnk_files_pattern(openvswitch_t, openvswitch_var_run_t, openvswitch_var_run_t)
files_pid_filetrans(openvswitch_t, openvswitch_var_run_t, { dir file lnk_file sock_file })

kernel_load_module(openvswitch_t)
kernel_read_network_state(openvswitch_t)
kernel_read_system_state(openvswitch_t)
kernel_request_load_module(openvswitch_t)
files_map_kernel_modules(openvswitch_t)
kernel_read_net_sysctls(openvswitch_t)
kernel_write_perf_event(openvswitch_t)

corenet_tcp_connect_xodbc_connect_port(openvswitch_t)
corenet_tcp_connect_ovsdb_port(openvswitch_t)
corenet_tcp_connect_openflow_port(openvswitch_t)
corenet_tcp_connect_openvswitch_port(openvswitch_t)
corenet_tcp_bind_generic_node(openvswitch_t)
corenet_tcp_bind_openvswitch_port(openvswitch_t)

corecmd_exec_bin(openvswitch_t)
corecmd_exec_shell(openvswitch_t)

dev_read_rand(openvswitch_t)
dev_read_urand(openvswitch_t)
dev_rw_sysfs(openvswitch_t)
dev_rw_vfio_dev(openvswitch_t)
corenet_rw_tun_tap_dev(openvswitch_t)
dev_rw_infiniband_dev(openvswitch_t)
dev_read_cpuid(openvswitch_t)

domain_use_interactive_fds(openvswitch_t)

files_read_kernel_modules(openvswitch_t)
files_load_kernel_modules(openvswitch_t)

fs_getattr_all_fs(openvswitch_t)
fs_search_cgroup_dirs(openvswitch_t)
fs_manage_hugetlbfs_files(openvswitch_t)
fs_manage_hugetlbfs_dirs(openvswitch_t)

auth_use_nsswitch(openvswitch_t)

logging_send_syslog_msg(openvswitch_t)

init_read_script_state(openvswitch_t)

modutils_exec_kmod(openvswitch_t)
modutils_list_module_config(openvswitch_t)
modutils_read_module_config(openvswitch_t)
modutils_read_module_deps(openvswitch_t)

sysnet_dns_name_resolve(openvswitch_t)

logging_send_audit_msgs(openvswitch_t)

write_sock_files_pattern(init_t, openvswitch_var_run_t, openvswitch_var_run_t)

storage_rw_inherited_fixed_disk_dev(openvswitch_t)

optional_policy(`
    hostname_exec(openvswitch_t)
')

optional_policy(`
	iptables_domtrans(openvswitch_t)
')

optional_policy(`
    plymouthd_exec_plymouth(openvswitch_t)
')

optional_policy(`
    neutron_read_state(openvswitch_t)
')

optional_policy(`
    networkmanager_read_state(openvswitch_t)
')

optional_policy(`
    virt_svirt_manage_tmp(openvswitch_t)
    virt_rw_svirt_image(openvswitch_t)
    virt_stream_connect_svirt(openvswitch_t)
    virt_rw_stream_sockets_svirt(openvswitch_t)
')

optional_policy(`
    seutil_domtrans_setfiles(openvswitch_t)
')
