]>
Commit | Line | Data |
---|---|---|
6939693f AD |
1 | package PVE::Network::Plugin; |
2 | ||
3 | use strict; | |
4 | use warnings; | |
5 | ||
6 | use PVE::Tools; | |
7 | use PVE::JSONSchema; | |
8 | use PVE::Cluster; | |
9 | ||
10 | use Data::Dumper; | |
11 | ||
12 | use base qw(PVE::SectionConfig); | |
13 | ||
14 | PVE::Cluster::cfs_register_file('network/transports.cfg', | |
15 | sub { __PACKAGE__->parse_config(@_); }, | |
16 | sub { __PACKAGE__->write_config(@_); }); | |
17 | ||
18 | my $defaultData = { | |
19 | ||
20 | propertyList => { | |
21 | type => { | |
22 | description => "Plugin type.", | |
23 | type => 'string', format => 'pve-configid', | |
24 | type => 'string', | |
25 | }, | |
26 | 'uplink-id' => { | |
27 | type => 'integer', | |
28 | minimum => 1, maximum => 4096, | |
29 | description => 'Uplink interface', | |
30 | }, | |
31 | }, | |
32 | }; | |
33 | ||
34 | sub private { | |
35 | return $defaultData; | |
36 | } | |
37 | ||
38 | sub parse_section_header { | |
39 | my ($class, $line) = @_; | |
40 | ||
41 | if ($line =~ m/^(\S+):\s*(\S+)\s*$/) { | |
42 | my ($type, $transportid) = (lc($1), $2); | |
43 | my $errmsg = undef; # set if you want to skip whole section | |
44 | eval { PVE::JSONSchema::pve_verify_configid($type); }; | |
45 | $errmsg = $@ if $@; | |
46 | my $config = {}; # to return additional attributes | |
47 | return ($type, $transportid, $errmsg, $config); | |
48 | } | |
49 | return undef; | |
50 | } | |
51 | ||
52 | sub generate_network_config { | |
53 | my ($class, $plugin_config, $node, $data, $ctime) = @_; | |
54 | ||
55 | die "please implement inside plugin"; | |
56 | } | |
57 | ||
58 | #helpers | |
59 | sub parse_tag_number_or_range { | |
60 | my ($str, $max, $tag) = @_; | |
61 | ||
62 | my @elements = split(/,/, $str); | |
63 | my $count = 0; | |
64 | my $allowed = undef; | |
65 | ||
66 | die "extraneous commas in list\n" if $str ne join(',', @elements); | |
67 | foreach my $item (@elements) { | |
68 | if ($item =~ m/^([0-9]+)-([0-9]+)$/) { | |
69 | $count += 2; | |
70 | my ($port1, $port2) = ($1, $2); | |
71 | die "invalid port '$port1'\n" if $port1 > $max; | |
72 | die "invalid port '$port2'\n" if $port2 > $max; | |
73 | die "backwards range '$port1:$port2' not allowed, did you mean '$port2:$port1'?\n" if $port1 > $port2; | |
74 | ||
75 | if ($tag && $tag >= $port1 && $tag <= $port2){ | |
76 | $allowed = 1; | |
77 | last; | |
78 | } | |
79 | ||
80 | } elsif ($item =~ m/^([0-9]+)$/) { | |
81 | $count += 1; | |
82 | my $port = $1; | |
83 | die "invalid port '$port'\n" if $port > $max; | |
84 | ||
85 | if ($tag && $tag == $port){ | |
86 | $allowed = 1; | |
87 | last; | |
88 | } | |
89 | } | |
90 | } | |
91 | die "tag $tag is not allowed" if $tag && !$allowed; | |
92 | ||
93 | return (scalar(@elements) > 1); | |
94 | } | |
95 | ||
96 | 1; |