New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

T791,T793: wireguard support #44

Closed
wants to merge 12 commits into
base: current
from

Conversation

Projects
None yet
3 participants
@hagbard-01
Member

hagbard-01 commented Aug 23, 2018

  • listen-port now optional
  • peers structured adjusted
  • fwmark implementation
  • validation for listen-port, fwmark changed/added

Now let's see what sonar means.

## optional settings
# listen-port
if c['interfaces'][intf]['lport']:

This comment has been minimized.

@vyosbot

vyosbot Aug 23, 2018

Collaborator

MINOR Bad indentation. Found 4 spaces, expected 8 rule

@vyosbot

vyosbot Aug 23, 2018

Collaborator

MINOR Bad indentation. Found 4 spaces, expected 8 rule

## optional settings
# listen-port
if c['interfaces'][intf]['lport']:
wg_config['listen-port'] = c['interfaces'][intf]['lport']

This comment has been minimized.

@vyosbot

vyosbot Aug 23, 2018

Collaborator

MINOR Bad indentation. Found 6 spaces, expected 12 rule

@vyosbot

vyosbot Aug 23, 2018

Collaborator

MINOR Bad indentation. Found 6 spaces, expected 12 rule

### persistent-keepalive
if c.exists(cnf + ' peer ' + p + ' persistent-keepalive'):
config_data['interfaces'][intfc]['peer'][p]['persistent-keepalive'] = c.return_value(cnf + ' peer ' + p + ' persistent-keepalive')
if c.exists(cnf + ' peer ' + p + ' persistent-keepalive'):

This comment has been minimized.

@vyosbot

vyosbot Aug 23, 2018

Collaborator

CRITICAL Refactor this code to not nest more than 4 "if", "for", "while", "try" and "with" statements. rule

@vyosbot

vyosbot Aug 23, 2018

Collaborator

CRITICAL Refactor this code to not nest more than 4 "if", "for", "while", "try" and "with" statements. rule

## endpoint
if c['interfaces'][intf]['peer'][p]['endpoint']:
wg_config['endpoint'] = c['interfaces'][intf]['peer'][p]['endpoint']

This comment has been minimized.

@vyosbot

vyosbot Aug 23, 2018

Collaborator

MINOR Bad indentation. Found 6 spaces, expected 12 rule

@vyosbot

vyosbot Aug 23, 2018

Collaborator

MINOR Bad indentation. Found 6 spaces, expected 12 rule

cmd += " allowed-ips "
for ap in wg_config['allowed-ips']:
if ap != wg_config['allowed-ips'][-1]:

This comment has been minimized.

@vyosbot

vyosbot Aug 23, 2018

Collaborator

MINOR Bad indentation. Found 6 spaces, expected 12 rule

@vyosbot

vyosbot Aug 23, 2018

Collaborator

MINOR Bad indentation. Found 6 spaces, expected 12 rule

## endpoint is only required if wg runs as client
if c['interfaces'][intf]['peer'][p]['endpoint']:
cmd += " endpoint " + c['interfaces'][intf]['peer'][p]['endpoint']
if wg_config['endpoint']:

This comment has been minimized.

@vyosbot

vyosbot Aug 23, 2018

Collaborator

MINOR Bad indentation. Found 4 spaces, expected 8 rule

@vyosbot

vyosbot Aug 23, 2018

Collaborator

MINOR Bad indentation. Found 4 spaces, expected 8 rule

if c['interfaces'][intf]['peer'][p]['endpoint']:
cmd += " endpoint " + c['interfaces'][intf]['peer'][p]['endpoint']
if wg_config['endpoint']:
cmd += " endpoint " + wg_config['endpoint']

This comment has been minimized.

@vyosbot

vyosbot Aug 23, 2018

Collaborator

MINOR Bad indentation. Found 6 spaces, expected 12 rule

@vyosbot

vyosbot Aug 23, 2018

Collaborator

MINOR Bad indentation. Found 6 spaces, expected 12 rule

sl.syslog(sl.LOG_NOTICE, "sudo " + cmd)
subprocess.call([ 'sudo ' + cmd], shell=True)
sl.syslog(sl.LOG_NOTICE, cmd)

This comment has been minimized.

@vyosbot

vyosbot Aug 23, 2018

Collaborator

MINOR Bad indentation. Found 4 spaces, expected 8 rule

@vyosbot

vyosbot Aug 23, 2018

Collaborator

MINOR Bad indentation. Found 4 spaces, expected 8 rule

sl.syslog(sl.LOG_NOTICE, "sudo " + cmd)
subprocess.call([ 'sudo ' + cmd], shell=True)
sl.syslog(sl.LOG_NOTICE, cmd)
subprocess.call([cmd], shell=True)

This comment has been minimized.

@vyosbot

vyosbot Aug 23, 2018

Collaborator

MINOR Bad indentation. Found 4 spaces, expected 8 rule

@vyosbot

vyosbot Aug 23, 2018

Collaborator

MINOR Bad indentation. Found 4 spaces, expected 8 rule

@hagbard-01

This comment has been minimized.

Show comment
Hide comment
@hagbard-01

hagbard-01 Aug 24, 2018

Member

Should I close this one because of all those error messages?

Member

hagbard-01 commented Aug 24, 2018

Should I close this one because of all those error messages?

@dmbaturin

This comment has been minimized.

Show comment
Hide comment
@dmbaturin

dmbaturin Aug 24, 2018

Member

@hagbard-01 Messages of @vyosbot ? Some of its comments are really silly, it's safe to ignore it.

Member

dmbaturin commented Aug 24, 2018

@hagbard-01 Messages of @vyosbot ? Some of its comments are really silly, it's safe to ignore it.

@dmbaturin

This comment has been minimized.

Show comment
Hide comment
@dmbaturin

dmbaturin Aug 24, 2018

Member

I'll need to manually review the code but my feeling is that in a number of cases Sonar is just wrong.

Member

dmbaturin commented Aug 24, 2018

I'll need to manually review the code but my feeling is that in a number of cases Sonar is just wrong.

@hagbard-01

This comment has been minimized.

Show comment
Hide comment
@hagbard-01

hagbard-01 Aug 24, 2018

Member

Cool, thx. Why did they show up, the previous PRs just made it through without any issues and the change I put into this one are really minor.

Member

hagbard-01 commented Aug 24, 2018

Cool, thx. Why did they show up, the previous PRs just made it through without any issues and the change I put into this one are really minor.

@dmbaturin

This comment has been minimized.

Show comment
Hide comment
@dmbaturin

dmbaturin Aug 24, 2018

Member

Frankly, no idea. It's also something to investigate.

Member

dmbaturin commented Aug 24, 2018

Frankly, no idea. It's also something to investigate.

@@ -194,7 +193,13 @@ def apply(c):
for addr in addr_add:
add_addr(intf, addr)
### persistent-keepalive
## mtu update
mtu = c['interfaces'][intf]['mtu']

This comment has been minimized.

@vyosbot

vyosbot Aug 24, 2018

Collaborator

MINOR Bad indentation. Found 6 spaces, expected 12 rule

@vyosbot

vyosbot Aug 24, 2018

Collaborator

MINOR Bad indentation. Found 6 spaces, expected 12 rule

### persistent-keepalive
## mtu update
mtu = c['interfaces'][intf]['mtu']
if mtu != 1420:

This comment has been minimized.

@vyosbot

vyosbot Aug 24, 2018

Collaborator

MINOR Bad indentation. Found 6 spaces, expected 12 rule

@vyosbot

vyosbot Aug 24, 2018

Collaborator

MINOR Bad indentation. Found 6 spaces, expected 12 rule

## mtu update
mtu = c['interfaces'][intf]['mtu']
if mtu != 1420:
sl.syslog(sl.LOG_NOTICE, "setting mtu to " + mtu + " on " + intf)

This comment has been minimized.

@vyosbot

vyosbot Aug 24, 2018

Collaborator

MINOR Bad indentation. Found 8 spaces, expected 16 rule

@vyosbot

vyosbot Aug 24, 2018

Collaborator

MINOR Bad indentation. Found 8 spaces, expected 16 rule

mtu = c['interfaces'][intf]['mtu']
if mtu != 1420:
sl.syslog(sl.LOG_NOTICE, "setting mtu to " + mtu + " on " + intf)
subprocess.call(['ip l set mtu ' + mtu + ' dev ' + intf + ' &>/dev/null'], shell=True)

This comment has been minimized.

@vyosbot

vyosbot Aug 24, 2018

Collaborator

MINOR Bad indentation. Found 8 spaces, expected 16 rule

@vyosbot

vyosbot Aug 24, 2018

Collaborator

MINOR Bad indentation. Found 8 spaces, expected 16 rule

### assemble wg command
cmd = "sudo wg set " + intf
cmd += " listen-port " + str(wg_config['listen-port'])
cmd += " private-key " + wg_config['private-key']

This comment has been minimized.

@vyosbot

vyosbot Aug 24, 2018

Collaborator

MINOR Bad indentation. Found 4 spaces, expected 8 rule

@vyosbot

vyosbot Aug 24, 2018

Collaborator

MINOR Bad indentation. Found 4 spaces, expected 8 rule

cmd = "sudo wg set " + intf
cmd += " listen-port " + str(wg_config['listen-port'])
cmd += " private-key " + wg_config['private-key']
cmd += " peer " + wg_config['peer']['pubkey']

This comment has been minimized.

@vyosbot

vyosbot Aug 24, 2018

Collaborator

MINOR Bad indentation. Found 4 spaces, expected 8 rule

@vyosbot

vyosbot Aug 24, 2018

Collaborator

MINOR Bad indentation. Found 4 spaces, expected 8 rule

cmd += " allowed-ips "
for ap in wg_config['allowed-ips']:

This comment has been minimized.

@vyosbot

vyosbot Aug 24, 2018

Collaborator

MINOR Bad indentation. Found 4 spaces, expected 8 rule

@vyosbot

vyosbot Aug 24, 2018

Collaborator

MINOR Bad indentation. Found 4 spaces, expected 8 rule

subprocess.call(['ip l set up dev ' + intf + ' &>/dev/null'], shell=True)
add_addr(intf, addr)
subprocess.call(['ip l set up dev ' + intf + ' mtu ' + c['interfaces'][intf]['mtu'] + ' &>/dev/null'], shell=True)

This comment has been minimized.

@vyosbot

vyosbot Aug 24, 2018

Collaborator

MINOR Bad indentation. Found 6 spaces, expected 12 rule

@vyosbot

vyosbot Aug 24, 2018

Collaborator

MINOR Bad indentation. Found 6 spaces, expected 12 rule

" private-key " + pk + \
" peer " + p
## mandatory settings
wg_config['peer']['pubkey'] = c['interfaces'][intf]['peer'][p]['pubkey']

This comment has been minimized.

@vyosbot

vyosbot Aug 24, 2018

Collaborator

MINOR Bad indentation. Found 4 spaces, expected 8 rule

@vyosbot

vyosbot Aug 24, 2018

Collaborator

MINOR Bad indentation. Found 4 spaces, expected 8 rule

" peer " + p
## mandatory settings
wg_config['peer']['pubkey'] = c['interfaces'][intf]['peer'][p]['pubkey']
wg_config['allowed-ips'] = c['interfaces'][intf]['peer'][p]['allowed-ips']

This comment has been minimized.

@vyosbot

vyosbot Aug 24, 2018

Collaborator

MINOR Bad indentation. Found 4 spaces, expected 8 rule

@vyosbot

vyosbot Aug 24, 2018

Collaborator

MINOR Bad indentation. Found 4 spaces, expected 8 rule

@hagbard-01

This comment has been minimized.

Show comment
Hide comment
@hagbard-01

hagbard-01 Aug 24, 2018

Member

added mtu implementation, let's see what happens.

Member

hagbard-01 commented Aug 24, 2018

added mtu implementation, let's see what happens.

for p in c['interfaces'][i]['peer']:
if not c['interfaces'][i]['peer'][p]['allowed-ips']:
raise ConfigError("allowed-ips required on interface " + i + " for peer " + p)
if not c['interfaces'][i]['peer'][p]['pubkey']:

This comment has been minimized.

@vyosbot

vyosbot Aug 24, 2018

Collaborator

MINOR Bad indentation. Found 8 spaces, expected 16 rule

@vyosbot

vyosbot Aug 24, 2018

Collaborator

MINOR Bad indentation. Found 8 spaces, expected 16 rule

if not c['interfaces'][i]['peer'][p]['allowed-ips']:
raise ConfigError("allowed-ips required on interface " + i + " for peer " + p)
if not c['interfaces'][i]['peer'][p]['pubkey']:
raise ConfigError("pubkey from your peer is mandatory on " + i + " for peer " + p)

This comment has been minimized.

@vyosbot

vyosbot Aug 24, 2018

Collaborator

MINOR Bad indentation. Found 10 spaces, expected 20 rule

@vyosbot

vyosbot Aug 24, 2018

Collaborator

MINOR Bad indentation. Found 10 spaces, expected 20 rule

## persistent-keepalive
if 'persistent-keepalive' in c['interfaces'][intf]['peer'][p]:
wg_config['keepalive'] = c['interfaces'][intf]['peer'][p]['persistent-keepalive']

This comment has been minimized.

@vyosbot

vyosbot Aug 25, 2018

Collaborator

MINOR Bad indentation. Found 6 spaces, expected 12 rule

@vyosbot

vyosbot Aug 25, 2018

Collaborator

MINOR Bad indentation. Found 6 spaces, expected 12 rule

wg_config['keepalive'] = c['interfaces'][intf]['peer'][p]['persistent-keepalive']
### assemble wg command
cmd = "sudo wg set " + intf

This comment has been minimized.

@vyosbot

vyosbot Aug 25, 2018

Collaborator

MINOR Bad indentation. Found 4 spaces, expected 8 rule

@vyosbot

vyosbot Aug 25, 2018

Collaborator

MINOR Bad indentation. Found 4 spaces, expected 8 rule

### assemble wg command
cmd = "sudo wg set " + intf
cmd += " listen-port " + str(wg_config['listen-port'])

This comment has been minimized.

@vyosbot

vyosbot Aug 25, 2018

Collaborator

MINOR Bad indentation. Found 4 spaces, expected 8 rule

@vyosbot

vyosbot Aug 25, 2018

Collaborator

MINOR Bad indentation. Found 4 spaces, expected 8 rule

if 'persistent-keepalive' in c['interfaces'][intf]['peer'][p]:
cmd += " persistent-keepalive " + str( c['interfaces'][intf]['peer'][p]['persistent-keepalive'])
if wg_config['keepalive'] != 0:

This comment has been minimized.

@vyosbot

vyosbot Aug 25, 2018

Collaborator

MINOR Bad indentation. Found 4 spaces, expected 8 rule

@vyosbot

vyosbot Aug 25, 2018

Collaborator

MINOR Bad indentation. Found 4 spaces, expected 8 rule

if 'persistent-keepalive' in c['interfaces'][intf]['peer'][p]:
cmd += " persistent-keepalive " + str( c['interfaces'][intf]['peer'][p]['persistent-keepalive'])
if wg_config['keepalive'] != 0:
cmd += " persistent-keepalive " + wg_config['keepalive']

This comment has been minimized.

@vyosbot

vyosbot Aug 25, 2018

Collaborator

MINOR Bad indentation. Found 6 spaces, expected 12 rule

@vyosbot

vyosbot Aug 25, 2018

Collaborator

MINOR Bad indentation. Found 6 spaces, expected 12 rule

if wg_config['keepalive'] != 0:
cmd += " persistent-keepalive " + wg_config['keepalive']
else:
cmd += " persistent-keepalive 0"

This comment has been minimized.

@vyosbot

vyosbot Aug 25, 2018

Collaborator

MINOR Bad indentation. Found 6 spaces, expected 12 rule

@vyosbot

vyosbot Aug 25, 2018

Collaborator

MINOR Bad indentation. Found 6 spaces, expected 12 rule

descr_eff = c_eff.return_effective_value(intf + ' description')
cnf_descr = c['interfaces'][intf]['descr']
if descr_eff != cnf_descr:
open('/sys/class/net/' + str(intf) + '/ifalias','w').write(str(cnf_descr))
with open('/sys/class/net/' + str(intf) + '/ifalias', 'w') as fh:

This comment has been minimized.

@vyosbot

vyosbot Aug 25, 2018

Collaborator

MINOR Bad indentation. Found 6 spaces, expected 12 rule

@vyosbot

vyosbot Aug 25, 2018

Collaborator

MINOR Bad indentation. Found 6 spaces, expected 12 rule

descr_eff = c_eff.return_effective_value(intf + ' description')
cnf_descr = c['interfaces'][intf]['descr']
if descr_eff != cnf_descr:
open('/sys/class/net/' + str(intf) + '/ifalias','w').write(str(cnf_descr))
with open('/sys/class/net/' + str(intf) + '/ifalias', 'w') as fh:
fh.write(str(cnf_descr))

This comment has been minimized.

@vyosbot

vyosbot Aug 25, 2018

Collaborator

MINOR Bad indentation. Found 8 spaces, expected 16 rule

@vyosbot

vyosbot Aug 25, 2018

Collaborator

MINOR Bad indentation. Found 8 spaces, expected 16 rule

descr_eff = c_eff.return_effective_value(intf + ' description')
cnf_descr = c['interfaces'][intf]['descr']
if descr_eff != cnf_descr:
open('/sys/class/net/' + str(intf) + '/ifalias','w').write(str(cnf_descr))
with open('/sys/class/net/' + str(intf) + '/ifalias', 'w') as fh:
fh.write(str(cnf_descr))
def configure_interface(c, intf):

This comment has been minimized.

@vyosbot

vyosbot Aug 25, 2018

Collaborator

CRITICAL Refactor this function to reduce its Cognitive Complexity from 18 to the 15 allowed. rule

@vyosbot

vyosbot Aug 25, 2018

Collaborator

CRITICAL Refactor this function to reduce its Cognitive Complexity from 18 to the 15 allowed. rule

def configure_interface(c, intf):
wg_config = {

This comment has been minimized.

@vyosbot

vyosbot Aug 25, 2018

Collaborator

MINOR Bad indentation. Found 2 spaces, expected 4 rule

@vyosbot

vyosbot Aug 25, 2018

Collaborator

MINOR Bad indentation. Found 2 spaces, expected 4 rule

)
if c.exists(cnf + ' peer ' + p + ' pubkey'):

This comment has been minimized.

@vyosbot

vyosbot Aug 25, 2018

Collaborator

CRITICAL Refactor this code to not nest more than 4 "if", "for", "while", "try" and "with" statements. rule
MINOR Bad indentation. Found 10 spaces, expected 20 rule

@vyosbot

vyosbot Aug 25, 2018

Collaborator

CRITICAL Refactor this code to not nest more than 4 "if", "for", "while", "try" and "with" statements. rule
MINOR Bad indentation. Found 10 spaces, expected 20 rule

)
if c.exists(cnf + ' peer ' + p + ' pubkey'):
config_data['interfaces'][intfc]['peer'][p]['pubkey'] = c.return_value(cnf + ' peer ' + p + ' pubkey')

This comment has been minimized.

@vyosbot

vyosbot Aug 25, 2018

Collaborator

MINOR Bad indentation. Found 12 spaces, expected 24 rule

@vyosbot

vyosbot Aug 25, 2018

Collaborator

MINOR Bad indentation. Found 12 spaces, expected 24 rule

@vyosbot

This comment has been minimized.

Show comment
Hide comment
@vyosbot

vyosbot Aug 25, 2018

Collaborator

SonarQube analysis reported 34 issues

  • CRITICAL 3 critical
  • MINOR 31 minor

Watch the comments in this conversation to review them.

Collaborator

vyosbot commented Aug 25, 2018

SonarQube analysis reported 34 issues

  • CRITICAL 3 critical
  • MINOR 31 minor

Watch the comments in this conversation to review them.

@hagbard-01 hagbard-01 closed this Aug 25, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment