mirror of
https://github.com/rancher/plugins.git
synced 2025-07-08 20:53:53 +00:00
21 lines
464 B
Go
21 lines
464 B
Go
|
package utils
|
||
|
|
||
|
import (
|
||
|
"crypto/sha512"
|
||
|
"fmt"
|
||
|
)
|
||
|
|
||
|
// 29 - len('CNI') - 2*len('-')
|
||
|
const maxNameLen = 16
|
||
|
|
||
|
// Generates a chain name to be used with iptables.
|
||
|
// Ensures that the generated name is less than
|
||
|
// 29 chars in length
|
||
|
func FormatChainName(name string, id string) string {
|
||
|
h := sha512.Sum512([]byte(id))
|
||
|
if len(name) > maxNameLen {
|
||
|
return fmt.Sprintf("CNI-%s-%x", name[:len(name)-maxNameLen], h[:8])
|
||
|
}
|
||
|
return fmt.Sprintf("CNI-%s-%x", name, h[:8])
|
||
|
}
|