network-utility 2.0.8 → 2.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c8b6e7268a3f3ebe7f9de7da912280f8682865d0634c2e0c3edd0d2b4b218893
4
- data.tar.gz: 8b03fe4bfd78f5a4911abedea9cefb1abd64b3281685d155ad2a30f91246a4fc
3
+ metadata.gz: 929c274aa699c68f118072411a17e530ded66edb4e67db3c2571f552ce648bdf
4
+ data.tar.gz: 0a40495971f768bb4069f5b03a7900b49fb6f98599eec6d998e60cd4548cc4a6
5
5
  SHA512:
6
- metadata.gz: 6fb10afaaacf6d75c57dc3935508ed6bedd503f9e52b41226cbd87f439700620f1f668bdecaa2c000e4f88172d440ddaaab154a0641d65f267758769a774297f
7
- data.tar.gz: 822d1d679bcc092fa2ffcd949d4276f84b4ae3766ee036b69ff28df52dad8a2a9d4cb335c8454ca2336e604eb9b09d362afa05e6dfcc22b38083e655f1a398a3
6
+ metadata.gz: e695e5cc3d7cc53b40cdb20a0867c86aeed12bd7b7cd9f1832e8693fc8aa26492fcc2eeacc80cbe10d6cfb7cf8150e695122472b943141b8ced813643d219f4d
7
+ data.tar.gz: 589671add2f94e6f9389fdd213f75696fc35f92e4db334e1da7a4bbb285617ea47df04b5bd294bb42724cc5fc857af93c0d47fc48b37bfdc160714132a874114
@@ -0,0 +1,204 @@
1
+
2
+ # CX600-X16A 访问控制列表
3
+
4
+ ```ruby
5
+ @sign << ['CX600-X16A', 'ACL']
6
+ @sign << ['CX600-X16A', 'resort']
7
+ @sign << ['CX600-X16A', 'detect_adv']
8
+ @sign << ['CX600-X16A', 'gen_rule']
9
+
10
+ module CX600_X16A
11
+ module_function
12
+
13
+ def ACL config
14
+ table = {}
15
+ number = nil
16
+ config.split("\n").each do|line|
17
+ number = line.split('number')[1].strip.to_i if line.include?('acl number') or line.include?('acl ipv6 number')
18
+ table[number] ||= {}
19
+ if line.include?('rule')
20
+ rule = line.split(' ')
21
+ table[number][rule[1].to_i] = rule[2..-1]
22
+ end
23
+ end
24
+ table.delete(nil)
25
+ return table
26
+ end
27
+
28
+ # 重排ACL序号,只对纯文本编排,注意最末行
29
+ def resort text, index # {[old,old]=>new}
30
+ packs,newlist = {},[]
31
+ index.each do|is,ni| packs[ni] = [] end
32
+ text.split("\n").each do|line|
33
+ items = line.split(' ')
34
+ id = items[1].to_i
35
+ index.each do|is,ni|
36
+ packs[ni] << items[2..-1].join(' ') if (is[0]..is[1]).include?(id)
37
+ end
38
+ newlist << "undo rule #{id}"
39
+ end
40
+ packs.each do|ni,pack|
41
+ pack.sort.each_with_index do|rule, si|
42
+ newlist << "rule #{ni.to_i+si.to_i} #{rule}"
43
+ end
44
+ end
45
+ return newlist.join("\n")
46
+ end
47
+
48
+ # INTEGER<1000-1999> Interface access-list(add to current using rules)
49
+ # INTEGER<10000-10999> MPLS access list (add to current using rules)
50
+ # INTEGER<2000-2999> Basic access-list(add to current using rules)
51
+ # INTEGER<3000-3999> Advanced access-list(add to current using rules)
52
+ # INTEGER<4000-4999> Specify a L2 ACL group(add to current using rules)
53
+ # ip-pool Specify IP pool configuration
54
+ # ipv6 ACL IPv6
55
+ # name Specify a named ACL
56
+ # number Specify a numbered ACL
57
+
58
+ PORTS = {
59
+ 137 => 'netbios-ns',
60
+ 138 => 'netbios-dgm',
61
+ 139 => 'netbios-ssn',
62
+ 19 => 'CHARgen',
63
+ 179 => 'bgp',
64
+ 514 => 'cmd',
65
+ 13 => 'daytime',
66
+ 9 => 'discard',
67
+ 53 => 'domain',
68
+ 7 => 'echo',
69
+ 512 => 'exec',
70
+ 79 => 'finger',
71
+ 21 => 'ftp',
72
+ 20 => 'ftp-data',
73
+ 70 => 'gopher',
74
+ 101 => 'hostname',
75
+ 194 => 'irc',
76
+ 543 => 'klogin',
77
+ 544 => 'kshell',
78
+ 513 => 'login',
79
+ 515 => 'lpd',
80
+ 119 => 'nntp',
81
+ 109 => 'pop2',
82
+ 110 => 'pop3',
83
+ 25 => 'smtp',
84
+ 111 => 'sunrpc',
85
+ 49 => 'tacacs',
86
+ 517 => 'talk',
87
+ 23 => 'telnet',
88
+ 37 => 'time',
89
+ 540 => 'uucp',
90
+ 43 => 'whois',
91
+ 80 => 'www'
92
+ }
93
+
94
+ # acl-adv rule
95
+ def detect_adv rule,index=nil
96
+ words = rule.instance_of?(String) ? rule.split(' ') : rule # text or array
97
+ # words: <action> <protocol> [<src>] [<dst>] [<tail>]
98
+ # <src> := [ source <sip> <smk> ] [ source-port [[eq|gt|lt <spt>]|[range <spt1> <spt2>]] ]
99
+ # <dst> := [ destination <dip> <dmk>] [ destination-port [[eq|gt|lt <dpt>]|[range <dpt1> <dpt2>]] ]
100
+ # <tail> := "PENDING"
101
+ ritle = {}
102
+ ritle['index'] = index if index
103
+ action,protocol = words[0..1]
104
+ ritle['action'] = action
105
+ ritle['protocol'] = protocol
106
+ ['source','destination'].each do|edge|
107
+ if words.include?(edge)
108
+ edge_ip = words[words.index(edge)+1]
109
+ unless edge_ip=='any'
110
+ if edge_ip.include?(':')
111
+ start_ip, ei_amask = IP.v6(edge_ip)
112
+ else
113
+ ei_amask_str = words[words.index(edge)+2]
114
+ ei_amask_str = '0.0.0.0' if ei_amask_str == '0'
115
+ start_ip,ei_amask = IP.v4(edge_ip),IP.v4(ei_amask_str)
116
+ end
117
+ end_ip = start_ip.clone + ei_amask.number
118
+ ritle[edge] = [start_ip.to_s, end_ip.to_s]
119
+ end
120
+ end
121
+ end
122
+ ['source-port', 'destination-port'].each do|port|
123
+ if words.include?(port)
124
+ op = words[words.index(port)+1]
125
+ range = case op
126
+ when 'range'
127
+ a, b = words[words.index(port)+2], words[words.index(port)+3]
128
+ a = PORTS.key(a) ? PORTS.key(a) : a.to_i
129
+ b = PORTS.key(b) ? PORTS.key(b) : b.to_i
130
+ [ a, b ]
131
+ when 'lt'
132
+ a = words[words.index(port)+2]
133
+ a = PORTS.key(a) ? PORTS.key(a) : a.to_i
134
+ [ 0, a ]
135
+ when 'gt'
136
+ a = words[words.index(port)+2]
137
+ a = PORTS.key(a) ? PORTS.key(a) : a.to_i
138
+ [ 65535, a ]
139
+ when 'eq'
140
+ a = words[words.index(port)+2]
141
+ a = PORTS.key(a) ? PORTS.key(a) : a.to_i
142
+ [ a, a ]
143
+ end.sort
144
+ ritle[port] = range
145
+ end
146
+ end
147
+ # TODO: tail
148
+ return ritle
149
+ end
150
+
151
+ # 查询规则1#
152
+ def in_range? ritle, target
153
+ tip = IP.v4(target[:ip])
154
+ tnum = tip.number
155
+ if ritle["destination"] && ritle["destination-port"]
156
+ si,ei = ritle["destination"].map{|i|IP.v4(i).number}
157
+ sp,ep = ritle["destination-port"]
158
+ return ritle if (si..ei).include?(tnum) && (sp..ep).include?(target[:port]) && ritle['action']==target[:action]
159
+ end
160
+ return nil
161
+ end
162
+
163
+ # 查询规则2#
164
+ def list_in_range? list, target
165
+ tip = IP.v4(target[:ip])
166
+ tnum = tip.number
167
+ set = []
168
+ list.each do|ritle|
169
+ if ritle["destination"] && ritle["destination-port"]
170
+ si,ei = ritle["destination"].map{|i|IP.v4(i).number}
171
+ sp,ep = ritle["destination-port"]
172
+ set << ritle if (si..ei).include?(tnum) && (sp..ep).include?(target[:port]) && ritle['action']==target[:action]
173
+ end
174
+ end
175
+ return set
176
+ end
177
+
178
+ # 生成规则:
179
+ # options = {
180
+ # index: 107,
181
+ # action: 'deny',
182
+ # protocol: 'tcp',
183
+ # sip: '1.1.1.1',
184
+ # sport: 80,
185
+ # dip: '2.2.2.2',
186
+ # dport: 443
187
+ # }
188
+ def gen_rule options
189
+ rule = ['rule']
190
+ return {'conf-error'=>"缺少必要参数:规则索引"} unless options[:index]
191
+ return {'conf-error'=>"缺少必要参数:动作"} unless options[:action]
192
+ return {'conf-error'=>"缺少必要参数:协议"} unless options[:protocol]
193
+ return {'runtime-error'=>"规则空位不足"} if options[:index]=='no slot'
194
+ rule << options[:index]
195
+ rule << options[:action]
196
+ rule << options[:protocol]
197
+ options[:sip] and rule << "source #{options[:sip]}"
198
+ options[:sport] and rule << "source-port eq #{options[:sport]}"
199
+ options[:dip] and rule << "destination #{options[:dip]}"
200
+ options[:dport] and rule << "destination-port eq #{options[:dport]}"
201
+ return {"operation"=>rule.join(" ")}
202
+ end
203
+ end
204
+ ```
@@ -0,0 +1,204 @@
1
+
2
+ # CX600-X8A 访问控制列表
3
+
4
+ ```ruby
5
+ @sign << ['CX600-X8A', 'ACL']
6
+ @sign << ['CX600-X8A', 'resort']
7
+ @sign << ['CX600-X8A', 'detect_adv']
8
+ @sign << ['CX600-X8A', 'gen_rule']
9
+
10
+ module CX600_X8A
11
+ module_function
12
+
13
+ def ACL config
14
+ table = {}
15
+ number = nil
16
+ config.split("\n").each do|line|
17
+ number = line.split('number')[1].strip.to_i if line.include?('acl number') or line.include?('acl ipv6 number')
18
+ table[number] ||= {}
19
+ if line.include?('rule')
20
+ rule = line.split(' ')
21
+ table[number][rule[1].to_i] = rule[2..-1]
22
+ end
23
+ end
24
+ table.delete(nil)
25
+ return table
26
+ end
27
+
28
+ # 重排ACL序号,只对纯文本编排,注意最末行
29
+ def resort text, index # {[old,old]=>new}
30
+ packs,newlist = {},[]
31
+ index.each do|is,ni| packs[ni] = [] end
32
+ text.split("\n").each do|line|
33
+ items = line.split(' ')
34
+ id = items[1].to_i
35
+ index.each do|is,ni|
36
+ packs[ni] << items[2..-1].join(' ') if (is[0]..is[1]).include?(id)
37
+ end
38
+ newlist << "undo rule #{id}"
39
+ end
40
+ packs.each do|ni,pack|
41
+ pack.sort.each_with_index do|rule, si|
42
+ newlist << "rule #{ni.to_i+si.to_i} #{rule}"
43
+ end
44
+ end
45
+ return newlist.join("\n")
46
+ end
47
+
48
+ # INTEGER<1000-1999> Interface access-list(add to current using rules)
49
+ # INTEGER<10000-10999> MPLS access list (add to current using rules)
50
+ # INTEGER<2000-2999> Basic access-list(add to current using rules)
51
+ # INTEGER<3000-3999> Advanced access-list(add to current using rules)
52
+ # INTEGER<4000-4999> Specify a L2 ACL group(add to current using rules)
53
+ # ip-pool Specify IP pool configuration
54
+ # ipv6 ACL IPv6
55
+ # name Specify a named ACL
56
+ # number Specify a numbered ACL
57
+
58
+ PORTS = {
59
+ 137 => 'netbios-ns',
60
+ 138 => 'netbios-dgm',
61
+ 139 => 'netbios-ssn',
62
+ 19 => 'CHARgen',
63
+ 179 => 'bgp',
64
+ 514 => 'cmd',
65
+ 13 => 'daytime',
66
+ 9 => 'discard',
67
+ 53 => 'domain',
68
+ 7 => 'echo',
69
+ 512 => 'exec',
70
+ 79 => 'finger',
71
+ 21 => 'ftp',
72
+ 20 => 'ftp-data',
73
+ 70 => 'gopher',
74
+ 101 => 'hostname',
75
+ 194 => 'irc',
76
+ 543 => 'klogin',
77
+ 544 => 'kshell',
78
+ 513 => 'login',
79
+ 515 => 'lpd',
80
+ 119 => 'nntp',
81
+ 109 => 'pop2',
82
+ 110 => 'pop3',
83
+ 25 => 'smtp',
84
+ 111 => 'sunrpc',
85
+ 49 => 'tacacs',
86
+ 517 => 'talk',
87
+ 23 => 'telnet',
88
+ 37 => 'time',
89
+ 540 => 'uucp',
90
+ 43 => 'whois',
91
+ 80 => 'www'
92
+ }
93
+
94
+ # acl-adv rule
95
+ def detect_adv rule,index=nil
96
+ words = rule.instance_of?(String) ? rule.split(' ') : rule # text or array
97
+ # words: <action> <protocol> [<src>] [<dst>] [<tail>]
98
+ # <src> := [ source <sip> <smk> ] [ source-port [[eq|gt|lt <spt>]|[range <spt1> <spt2>]] ]
99
+ # <dst> := [ destination <dip> <dmk>] [ destination-port [[eq|gt|lt <dpt>]|[range <dpt1> <dpt2>]] ]
100
+ # <tail> := "PENDING"
101
+ ritle = {}
102
+ ritle['index'] = index if index
103
+ action,protocol = words[0..1]
104
+ ritle['action'] = action
105
+ ritle['protocol'] = protocol
106
+ ['source','destination'].each do|edge|
107
+ if words.include?(edge)
108
+ edge_ip = words[words.index(edge)+1]
109
+ unless edge_ip=='any'
110
+ if edge_ip.include?(':')
111
+ start_ip, ei_amask = IP.v6(edge_ip)
112
+ else
113
+ ei_amask_str = words[words.index(edge)+2]
114
+ ei_amask_str = '0.0.0.0' if ei_amask_str == '0'
115
+ start_ip,ei_amask = IP.v4(edge_ip),IP.v4(ei_amask_str)
116
+ end
117
+ end_ip = start_ip.clone + ei_amask.number
118
+ ritle[edge] = [start_ip.to_s, end_ip.to_s]
119
+ end
120
+ end
121
+ end
122
+ ['source-port', 'destination-port'].each do|port|
123
+ if words.include?(port)
124
+ op = words[words.index(port)+1]
125
+ range = case op
126
+ when 'range'
127
+ a, b = words[words.index(port)+2], words[words.index(port)+3]
128
+ a = PORTS.key(a) ? PORTS.key(a) : a.to_i
129
+ b = PORTS.key(b) ? PORTS.key(b) : b.to_i
130
+ [ a, b ]
131
+ when 'lt'
132
+ a = words[words.index(port)+2]
133
+ a = PORTS.key(a) ? PORTS.key(a) : a.to_i
134
+ [ 0, a ]
135
+ when 'gt'
136
+ a = words[words.index(port)+2]
137
+ a = PORTS.key(a) ? PORTS.key(a) : a.to_i
138
+ [ 65535, a ]
139
+ when 'eq'
140
+ a = words[words.index(port)+2]
141
+ a = PORTS.key(a) ? PORTS.key(a) : a.to_i
142
+ [ a, a ]
143
+ end.sort
144
+ ritle[port] = range
145
+ end
146
+ end
147
+ # TODO: tail
148
+ return ritle
149
+ end
150
+
151
+ # 查询规则1#
152
+ def in_range? ritle, target
153
+ tip = IP.v4(target[:ip])
154
+ tnum = tip.number
155
+ if ritle["destination"] && ritle["destination-port"]
156
+ si,ei = ritle["destination"].map{|i|IP.v4(i).number}
157
+ sp,ep = ritle["destination-port"]
158
+ return ritle if (si..ei).include?(tnum) && (sp..ep).include?(target[:port]) && ritle['action']==target[:action]
159
+ end
160
+ return nil
161
+ end
162
+
163
+ # 查询规则2#
164
+ def list_in_range? list, target
165
+ tip = IP.v4(target[:ip])
166
+ tnum = tip.number
167
+ set = []
168
+ list.each do|ritle|
169
+ if ritle["destination"] && ritle["destination-port"]
170
+ si,ei = ritle["destination"].map{|i|IP.v4(i).number}
171
+ sp,ep = ritle["destination-port"]
172
+ set << ritle if (si..ei).include?(tnum) && (sp..ep).include?(target[:port]) && ritle['action']==target[:action]
173
+ end
174
+ end
175
+ return set
176
+ end
177
+
178
+ # 生成规则:
179
+ # options = {
180
+ # index: 107,
181
+ # action: 'deny',
182
+ # protocol: 'tcp',
183
+ # sip: '1.1.1.1',
184
+ # sport: 80,
185
+ # dip: '2.2.2.2',
186
+ # dport: 443
187
+ # }
188
+ def gen_rule options
189
+ rule = ['rule']
190
+ return {'conf-error'=>"缺少必要参数:规则索引"} unless options[:index]
191
+ return {'conf-error'=>"缺少必要参数:动作"} unless options[:action]
192
+ return {'conf-error'=>"缺少必要参数:协议"} unless options[:protocol]
193
+ return {'runtime-error'=>"规则空位不足"} if options[:index]=='no slot'
194
+ rule << options[:index]
195
+ rule << options[:action]
196
+ rule << options[:protocol]
197
+ options[:sip] and rule << "source #{options[:sip]}"
198
+ options[:sport] and rule << "source-port eq #{options[:sport]}"
199
+ options[:dip] and rule << "destination #{options[:dip]}"
200
+ options[:dport] and rule << "destination-port eq #{options[:dport]}"
201
+ return {"operation"=>rule.join(" ")}
202
+ end
203
+ end
204
+ ```
@@ -0,0 +1,139 @@
1
+ # CX600-X16A bgp
2
+
3
+ ```ruby
4
+ @sign << ['CX600-X16A', 'bgp']
5
+ @sign << ['CX600-X16A', 'bgp地址族']
6
+ @sign << ['CX600-X16A', '宣告网段解析']
7
+
8
+ module CX600_X16A
9
+ module_function
10
+
11
+ def bgp bgp配置
12
+ address_family, non_af_conf = self.bgp地址族 bgp配置
13
+ bgp, afs = {}, {}
14
+ non_af_conf.each do|line|
15
+ if line.strip[0..4]=='group'
16
+ groupname,mode = line.split(' ')[1..2]
17
+ bgp['group'] ||= {}
18
+ bgp['group'][groupname] ||= {}
19
+ bgp['group'][groupname].merge!('mode' => mode)
20
+ elsif line.strip[0..3]=='peer'
21
+ afname = 'global'
22
+ words = line.split(' ')
23
+ peername,attribute = words[1..2]
24
+ value = words[3..-1].join(" ")
25
+ afs[afname] ||= {}
26
+ afs[afname]['peer'] ||= {}
27
+ afs[afname]['peer'][peername] ||= {}
28
+ if value.empty?
29
+ afs[afname]['peer'][peername][attribute] = true
30
+ else
31
+ unless afs[afname]['peer'][peername]
32
+ afs[afname]['peer'][peername][attribute] ||= []
33
+ afs[afname]['peer'][peername][attribute] << value
34
+ else
35
+ afs[afname]['peer'][peername][attribute] = value
36
+ end
37
+ end
38
+ else
39
+ words = line.split(' ')
40
+ attribute = words[0]
41
+ value = words[1..-1].join(" ")
42
+ bgp[attribute] ||= []
43
+ if value.empty?
44
+ bgp[attribute] << true
45
+ else
46
+ bgp[attribute] << value
47
+ end
48
+ end
49
+ end
50
+ address_family.each do|afname, afconf|
51
+ afs[afname] ||= {}
52
+ afconf.each do|line|
53
+ if line.strip[0..3]=='peer'
54
+ words = line.split(' ')
55
+ peername,attribute = words[1..2]
56
+ value = words[3..-1].join(" ")
57
+ if (bgp['group']||{})[peername]
58
+ if value.empty?
59
+ bgp['group'][peername][attribute] = true
60
+ else
61
+ bgp['group'][peername][attribute] ||= []
62
+ bgp['group'][peername][attribute] << value
63
+ end
64
+ else
65
+ afs[afname]['peer'] ||= {}
66
+ afs[afname]['peer'][peername] ||= {}
67
+ if value.empty?
68
+ afs[afname]['peer'][peername][attribute] = true
69
+ else
70
+ afs[afname]['peer'][peername][attribute] ||= []
71
+ afs[afname]['peer'][peername][attribute] << value
72
+ end
73
+ end
74
+ elsif line.strip[0..4]=='group'
75
+ groupname = line.split(' ')[1]
76
+ bgp['group'] ||= {}
77
+ bgp['group'][groupname] ||= {}
78
+ else
79
+ words = line.split(' ')
80
+ attribute = words[0]
81
+ value = words[1..-1].join(" ")
82
+ if value.empty?
83
+ afs[afname][attribute] = true
84
+ else
85
+ afs[afname][attribute] ||= []
86
+ afs[afname][attribute] << value
87
+ end
88
+ end
89
+ end
90
+ end
91
+ bgp.merge!('address-family'=>afs)
92
+ return bgp
93
+ end
94
+
95
+ def bgp地址族 bgp配置
96
+ address_family = {};non_af_conf = []
97
+ af_begin = false; af_name = 'global'
98
+ bgp配置.join("\n").split("\n").each do|line|
99
+ if line[0..11]==' ipv4-family' || line[0..11]==' ipv6-family'
100
+ af_begin = true
101
+ af_name = line.strip.gsub(' ','-')
102
+ address_family[af_name] ||= []
103
+ end
104
+ if line[0..1]==' #' # af_end
105
+ af_begin = false
106
+ af_name = 'global'
107
+ elsif line[0]=='#' # bgp_end or no-finisher
108
+ af_begin = false
109
+ af_name = 'global'
110
+ end
111
+ if af_begin
112
+ address_family[af_name] << line
113
+ else
114
+ non_af_conf << line unless line==' #'
115
+ end
116
+ end
117
+ return address_family, non_af_conf
118
+ end
119
+
120
+ def 宣告网段解析 配置散列
121
+ ranges = []
122
+ 配置散列['bgp'].each do|segment|
123
+ bgps = segment.match_paragraph("\n ipv4-family unicast", "\n #")
124
+ bgps.each do|bgp|
125
+ bgp.split("\n").each do|line|
126
+ if line.include?('network ') && line.strip.split(' ').size > 2
127
+ words = line.split(' ')
128
+ address, netmask = line.split(' ')[1].include?(':') ? IP.v6("#{words[1]}/#{words[2]}") : IP.v4("#{words[1]}/#{words[2]}")
129
+ network = address.network_with netmask
130
+ route_policy = words.index('route-policy') ? words[words.index('route-policy')+1] : ''
131
+ ranges << [ 'bgp', network.to_s, netmask.to_s, route_policy ]
132
+ end
133
+ end
134
+ end
135
+ end
136
+ return ranges
137
+ end
138
+ end
139
+ ```
@@ -0,0 +1,139 @@
1
+ # CX600-X8A bgp
2
+
3
+ ```ruby
4
+ @sign << ['CX600-X8A', 'bgp']
5
+ @sign << ['CX600-X8A', 'bgp地址族']
6
+ @sign << ['CX600-X8A', '宣告网段解析']
7
+
8
+ module CX600_X8A
9
+ module_function
10
+
11
+ def bgp bgp配置
12
+ address_family, non_af_conf = self.bgp地址族 bgp配置
13
+ bgp, afs = {}, {}
14
+ non_af_conf.each do|line|
15
+ if line.strip[0..4]=='group'
16
+ groupname,mode = line.split(' ')[1..2]
17
+ bgp['group'] ||= {}
18
+ bgp['group'][groupname] ||= {}
19
+ bgp['group'][groupname].merge!('mode' => mode)
20
+ elsif line.strip[0..3]=='peer'
21
+ afname = 'global'
22
+ words = line.split(' ')
23
+ peername,attribute = words[1..2]
24
+ value = words[3..-1].join(" ")
25
+ afs[afname] ||= {}
26
+ afs[afname]['peer'] ||= {}
27
+ afs[afname]['peer'][peername] ||= {}
28
+ if value.empty?
29
+ afs[afname]['peer'][peername][attribute] = true
30
+ else
31
+ unless afs[afname]['peer'][peername]
32
+ afs[afname]['peer'][peername][attribute] ||= []
33
+ afs[afname]['peer'][peername][attribute] << value
34
+ else
35
+ afs[afname]['peer'][peername][attribute] = value
36
+ end
37
+ end
38
+ else
39
+ words = line.split(' ')
40
+ attribute = words[0]
41
+ value = words[1..-1].join(" ")
42
+ bgp[attribute] ||= []
43
+ if value.empty?
44
+ bgp[attribute] << true
45
+ else
46
+ bgp[attribute] << value
47
+ end
48
+ end
49
+ end
50
+ address_family.each do|afname, afconf|
51
+ afs[afname] ||= {}
52
+ afconf.each do|line|
53
+ if line.strip[0..3]=='peer'
54
+ words = line.split(' ')
55
+ peername,attribute = words[1..2]
56
+ value = words[3..-1].join(" ")
57
+ if (bgp['group']||{})[peername]
58
+ if value.empty?
59
+ bgp['group'][peername][attribute] = true
60
+ else
61
+ bgp['group'][peername][attribute] ||= []
62
+ bgp['group'][peername][attribute] << value
63
+ end
64
+ else
65
+ afs[afname]['peer'] ||= {}
66
+ afs[afname]['peer'][peername] ||= {}
67
+ if value.empty?
68
+ afs[afname]['peer'][peername][attribute] = true
69
+ else
70
+ afs[afname]['peer'][peername][attribute] ||= []
71
+ afs[afname]['peer'][peername][attribute] << value
72
+ end
73
+ end
74
+ elsif line.strip[0..4]=='group'
75
+ groupname = line.split(' ')[1]
76
+ bgp['group'] ||= {}
77
+ bgp['group'][groupname] ||= {}
78
+ else
79
+ words = line.split(' ')
80
+ attribute = words[0]
81
+ value = words[1..-1].join(" ")
82
+ if value.empty?
83
+ afs[afname][attribute] = true
84
+ else
85
+ afs[afname][attribute] ||= []
86
+ afs[afname][attribute] << value
87
+ end
88
+ end
89
+ end
90
+ end
91
+ bgp.merge!('address-family'=>afs)
92
+ return bgp
93
+ end
94
+
95
+ def bgp地址族 bgp配置
96
+ address_family = {};non_af_conf = []
97
+ af_begin = false; af_name = 'global'
98
+ bgp配置.join("\n").split("\n").each do|line|
99
+ if line[0..11]==' ipv4-family' || line[0..11]==' ipv6-family'
100
+ af_begin = true
101
+ af_name = line.strip.gsub(' ','-')
102
+ address_family[af_name] ||= []
103
+ end
104
+ if line[0..1]==' #' # af_end
105
+ af_begin = false
106
+ af_name = 'global'
107
+ elsif line[0]=='#' # bgp_end or no-finisher
108
+ af_begin = false
109
+ af_name = 'global'
110
+ end
111
+ if af_begin
112
+ address_family[af_name] << line
113
+ else
114
+ non_af_conf << line unless line==' #'
115
+ end
116
+ end
117
+ return address_family, non_af_conf
118
+ end
119
+
120
+ def 宣告网段解析 配置散列
121
+ ranges = []
122
+ 配置散列['bgp'].each do|segment|
123
+ bgps = segment.match_paragraph("\n ipv4-family unicast", "\n #")
124
+ bgps.each do|bgp|
125
+ bgp.split("\n").each do|line|
126
+ if line.include?('network ') && line.strip.split(' ').size > 2
127
+ words = line.split(' ')
128
+ address, netmask = line.split(' ')[1].include?(':') ? IP.v6("#{words[1]}/#{words[2]}") : IP.v4("#{words[1]}/#{words[2]}")
129
+ network = address.network_with netmask
130
+ route_policy = words.index('route-policy') ? words[words.index('route-policy')+1] : ''
131
+ ranges << [ 'bgp', network.to_s, netmask.to_s, route_policy ]
132
+ end
133
+ end
134
+ end
135
+ end
136
+ return ranges
137
+ end
138
+ end
139
+ ```
@@ -39,10 +39,10 @@ module ME60_16
39
39
  words = line.split(' ')
40
40
  attribute = words[0]
41
41
  value = words[1..-1].join(" ")
42
+ bgp[attribute] ||= []
42
43
  if value.empty?
43
- bgp[attribute] = true
44
+ bgp[attribute] << true
44
45
  else
45
- bgp[attribute] ||= []
46
46
  bgp[attribute] << value
47
47
  end
48
48
  end
@@ -39,10 +39,10 @@ module ME60_X16
39
39
  words = line.split(' ')
40
40
  attribute = words[0]
41
41
  value = words[1..-1].join(" ")
42
+ bgp[attribute] ||= []
42
43
  if value.empty?
43
- bgp[attribute] = true
44
+ bgp[attribute] << true
44
45
  else
45
- bgp[attribute] ||= []
46
46
  bgp[attribute] << value
47
47
  end
48
48
  end
@@ -39,10 +39,10 @@ module NE40E_X16
39
39
  words = line.split(' ')
40
40
  attribute = words[0]
41
41
  value = words[1..-1].join(" ")
42
+ bgp[attribute] ||= []
42
43
  if value.empty?
43
- bgp[attribute] = true
44
+ bgp[attribute] << true
44
45
  else
45
- bgp[attribute] ||= []
46
46
  bgp[attribute] << value
47
47
  end
48
48
  end
@@ -39,10 +39,10 @@ module NE40E_X16A
39
39
  words = line.split(' ')
40
40
  attribute = words[0]
41
41
  value = words[1..-1].join(" ")
42
+ bgp[attribute] ||= []
42
43
  if value.empty?
43
- bgp[attribute] = true
44
+ bgp[attribute] << true
44
45
  else
45
- bgp[attribute] ||= []
46
46
  bgp[attribute] << value
47
47
  end
48
48
  end
@@ -39,10 +39,10 @@ module NE40E_X8
39
39
  words = line.split(' ')
40
40
  attribute = words[0]
41
41
  value = words[1..-1].join(" ")
42
+ bgp[attribute] ||= []
42
43
  if value.empty?
43
- bgp[attribute] = true
44
+ bgp[attribute] << true
44
45
  else
45
- bgp[attribute] ||= []
46
46
  bgp[attribute] << value
47
47
  end
48
48
  end
@@ -2,11 +2,122 @@
2
2
  # NE40E BGP
3
3
 
4
4
  ```ruby
5
+ @sign << ['NE40E', 'bgp']
6
+ @sign << ['NE40E', 'bgp地址族']
5
7
  @sign << ['NE40E', '宣告网段解析']
6
8
 
7
9
  module NE40E
8
10
  module_function
9
11
 
12
+ def bgp bgp配置
13
+ address_family, non_af_conf = self.bgp地址族 bgp配置
14
+ bgp, afs = {}, {}
15
+ non_af_conf.each do|line|
16
+ if line.strip[0..4]=='group'
17
+ groupname,mode = line.split(' ')[1..2]
18
+ bgp['group'] ||= {}
19
+ bgp['group'][groupname] ||= {}
20
+ bgp['group'][groupname].merge!('mode' => mode)
21
+ elsif line.strip[0..3]=='peer'
22
+ afname = 'global'
23
+ words = line.split(' ')
24
+ peername,attribute = words[1..2]
25
+ value = words[3..-1].join(" ")
26
+ afs[afname] ||= {}
27
+ afs[afname]['peer'] ||= {}
28
+ afs[afname]['peer'][peername] ||= {}
29
+ if value.empty?
30
+ afs[afname]['peer'][peername][attribute] = true
31
+ else
32
+ unless afs[afname]['peer'][peername]
33
+ afs[afname]['peer'][peername][attribute] ||= []
34
+ afs[afname]['peer'][peername][attribute] << value
35
+ else
36
+ afs[afname]['peer'][peername][attribute] = value
37
+ end
38
+ end
39
+ else
40
+ words = line.split(' ')
41
+ attribute = words[0]
42
+ value = words[1..-1].join(" ")
43
+ bgp[attribute] ||= []
44
+ if value.empty?
45
+ bgp[attribute] << true
46
+ else
47
+ bgp[attribute] << value
48
+ end
49
+ end
50
+ end
51
+ address_family.each do|afname, afconf|
52
+ afs[afname] ||= {}
53
+ afconf.each do|line|
54
+ if line.strip[0..3]=='peer'
55
+ words = line.split(' ')
56
+ peername,attribute = words[1..2]
57
+ value = words[3..-1].join(" ")
58
+ if (bgp['group']||{})[peername]
59
+ if value.empty?
60
+ bgp['group'][peername][attribute] = true
61
+ else
62
+ bgp['group'][peername][attribute] ||= []
63
+ bgp['group'][peername][attribute] << value
64
+ end
65
+ else
66
+ afs[afname]['peer'] ||= {}
67
+ afs[afname]['peer'][peername] ||= {}
68
+ if value.empty?
69
+ afs[afname]['peer'][peername][attribute] = true
70
+ else
71
+ afs[afname]['peer'][peername][attribute] ||= []
72
+ afs[afname]['peer'][peername][attribute] << value
73
+ end
74
+ end
75
+ elsif line.strip[0..4]=='group'
76
+ groupname = line.split(' ')[1]
77
+ bgp['group'] ||= {}
78
+ bgp['group'][groupname] ||= {}
79
+ else
80
+ words = line.split(' ')
81
+ attribute = words[0]
82
+ value = words[1..-1].join(" ")
83
+ if value.empty?
84
+ afs[afname][attribute] = true
85
+ else
86
+ afs[afname][attribute] ||= []
87
+ afs[afname][attribute] << value
88
+ end
89
+ end
90
+ end
91
+ end
92
+ bgp.merge!('address-family'=>afs)
93
+ return bgp
94
+ end
95
+
96
+ def bgp地址族 bgp配置
97
+ address_family = {};non_af_conf = []
98
+ af_begin = false; af_name = 'global'
99
+ bgp配置.join("\n").split("\n").each do|line|
100
+ if line[0..11]==' ipv4-family' || line[0..11]==' ipv6-family'
101
+ af_begin = true
102
+ af_name = line.strip.gsub(' ','-')
103
+ address_family[af_name] ||= []
104
+ end
105
+ if line[0..1]==' #' # af_end
106
+ af_begin = false
107
+ af_name = 'global'
108
+ elsif line[0]=='#' # bgp_end or no-finisher
109
+ af_begin = false
110
+ af_name = 'global'
111
+ end
112
+ if af_begin
113
+ address_family[af_name] << line
114
+ else
115
+ non_af_conf << line unless line==' #'
116
+ end
117
+ end
118
+ return address_family, non_af_conf
119
+ end
120
+
10
121
  def 宣告网段解析 配置散列
11
122
  ranges = []
12
123
  配置散列['bgp'].each do|segment|
@@ -39,10 +39,10 @@ module NE5000E_20
39
39
  words = line.split(' ')
40
40
  attribute = words[0]
41
41
  value = words[1..-1].join(" ")
42
+ bgp[attribute] ||= []
42
43
  if value.empty?
43
- bgp[attribute] = true
44
+ bgp[attribute] << true
44
45
  else
45
- bgp[attribute] ||= []
46
46
  bgp[attribute] << value
47
47
  end
48
48
  end
@@ -39,10 +39,10 @@ module NE5000E_X16
39
39
  words = line.split(' ')
40
40
  attribute = words[0]
41
41
  value = words[1..-1].join(" ")
42
+ bgp[attribute] ||= []
42
43
  if value.empty?
43
- bgp[attribute] = true
44
+ bgp[attribute] << true
44
45
  else
45
- bgp[attribute] ||= []
46
46
  bgp[attribute] << value
47
47
  end
48
48
  end
@@ -39,10 +39,10 @@ module NE5000E_X16A
39
39
  words = line.split(' ')
40
40
  attribute = words[0]
41
41
  value = words[1..-1].join(" ")
42
+ bgp[attribute] ||= []
42
43
  if value.empty?
43
- bgp[attribute] = true
44
+ bgp[attribute] << true
44
45
  else
45
- bgp[attribute] ||= []
46
46
  bgp[attribute] << value
47
47
  end
48
48
  end
@@ -2,11 +2,122 @@
2
2
  # NE80E BGP
3
3
 
4
4
  ```ruby
5
+ @sign << ['NE80E', 'bgp']
6
+ @sign << ['NE80E', 'bgp地址族']
5
7
  @sign << ['NE80E', '宣告网段解析']
6
8
 
7
9
  module NE80E
8
10
  module_function
9
11
 
12
+ def bgp bgp配置
13
+ address_family, non_af_conf = self.bgp地址族 bgp配置
14
+ bgp, afs = {}, {}
15
+ non_af_conf.each do|line|
16
+ if line.strip[0..4]=='group'
17
+ groupname,mode = line.split(' ')[1..2]
18
+ bgp['group'] ||= {}
19
+ bgp['group'][groupname] ||= {}
20
+ bgp['group'][groupname].merge!('mode' => mode)
21
+ elsif line.strip[0..3]=='peer'
22
+ afname = 'global'
23
+ words = line.split(' ')
24
+ peername,attribute = words[1..2]
25
+ value = words[3..-1].join(" ")
26
+ afs[afname] ||= {}
27
+ afs[afname]['peer'] ||= {}
28
+ afs[afname]['peer'][peername] ||= {}
29
+ if value.empty?
30
+ afs[afname]['peer'][peername][attribute] = true
31
+ else
32
+ unless afs[afname]['peer'][peername]
33
+ afs[afname]['peer'][peername][attribute] ||= []
34
+ afs[afname]['peer'][peername][attribute] << value
35
+ else
36
+ afs[afname]['peer'][peername][attribute] = value
37
+ end
38
+ end
39
+ else
40
+ words = line.split(' ')
41
+ attribute = words[0]
42
+ value = words[1..-1].join(" ")
43
+ bgp[attribute] ||= []
44
+ if value.empty?
45
+ bgp[attribute] << true
46
+ else
47
+ bgp[attribute] << value
48
+ end
49
+ end
50
+ end
51
+ address_family.each do|afname, afconf|
52
+ afs[afname] ||= {}
53
+ afconf.each do|line|
54
+ if line.strip[0..3]=='peer'
55
+ words = line.split(' ')
56
+ peername,attribute = words[1..2]
57
+ value = words[3..-1].join(" ")
58
+ if (bgp['group']||{})[peername]
59
+ if value.empty?
60
+ bgp['group'][peername][attribute] = true
61
+ else
62
+ bgp['group'][peername][attribute] ||= []
63
+ bgp['group'][peername][attribute] << value
64
+ end
65
+ else
66
+ afs[afname]['peer'] ||= {}
67
+ afs[afname]['peer'][peername] ||= {}
68
+ if value.empty?
69
+ afs[afname]['peer'][peername][attribute] = true
70
+ else
71
+ afs[afname]['peer'][peername][attribute] ||= []
72
+ afs[afname]['peer'][peername][attribute] << value
73
+ end
74
+ end
75
+ elsif line.strip[0..4]=='group'
76
+ groupname = line.split(' ')[1]
77
+ bgp['group'] ||= {}
78
+ bgp['group'][groupname] ||= {}
79
+ else
80
+ words = line.split(' ')
81
+ attribute = words[0]
82
+ value = words[1..-1].join(" ")
83
+ if value.empty?
84
+ afs[afname][attribute] = true
85
+ else
86
+ afs[afname][attribute] ||= []
87
+ afs[afname][attribute] << value
88
+ end
89
+ end
90
+ end
91
+ end
92
+ bgp.merge!('address-family'=>afs)
93
+ return bgp
94
+ end
95
+
96
+ def bgp地址族 bgp配置
97
+ address_family = {};non_af_conf = []
98
+ af_begin = false; af_name = 'global'
99
+ bgp配置.join("\n").split("\n").each do|line|
100
+ if line[0..11]==' ipv4-family' || line[0..11]==' ipv6-family'
101
+ af_begin = true
102
+ af_name = line.strip.gsub(' ','-')
103
+ address_family[af_name] ||= []
104
+ end
105
+ if line[0..1]==' #' # af_end
106
+ af_begin = false
107
+ af_name = 'global'
108
+ elsif line[0]=='#' # bgp_end or no-finisher
109
+ af_begin = false
110
+ af_name = 'global'
111
+ end
112
+ if af_begin
113
+ address_family[af_name] << line
114
+ else
115
+ non_af_conf << line unless line==' #'
116
+ end
117
+ end
118
+ return address_family, non_af_conf
119
+ end
120
+
10
121
  def 宣告网段解析 配置散列
11
122
  ranges = []
12
123
  配置散列['bgp'].each do|segment|
data/network.rb CHANGED
@@ -26,5 +26,5 @@
26
26
  ].each{|mod|require mod}
27
27
 
28
28
  module Network
29
- VERSION = '2.0.8'
29
+ VERSION = '2.0.10'
30
30
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: network-utility
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.8
4
+ version: 2.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt
@@ -54,6 +54,8 @@ files:
54
54
  - document/acl-CR16018-F.md
55
55
  - document/acl-CR19000-20.md
56
56
  - document/acl-CRS-16.md
57
+ - document/acl-CX600-X16A.md
58
+ - document/acl-CX600-X8A.md
57
59
  - document/acl-M6000-16E.md
58
60
  - document/acl-M6000-18S.md
59
61
  - document/acl-M6000-8.md
@@ -76,6 +78,8 @@ files:
76
78
  - document/bgp-CR16018-F.md
77
79
  - document/bgp-CR19000-20.md
78
80
  - document/bgp-CRS-16.md
81
+ - document/bgp-CX600-X16A.md
82
+ - document/bgp-CX600-X8A.md
79
83
  - document/bgp-M6000-16E.md
80
84
  - document/bgp-M6000-18S.md
81
85
  - document/bgp-M6000-8.md