From patchwork Fri Nov 15 19:44:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nick Rosbrook X-Patchwork-Id: 11247029 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CC0AC1393 for ; Fri, 15 Nov 2019 19:46:46 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A7C562073A for ; Fri, 15 Nov 2019 19:46:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="oSOHWPur" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A7C562073A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iVhXC-0001US-VU; Fri, 15 Nov 2019 19:45:34 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iVhXC-0001U3-Gi for xen-devel@lists.xenproject.org; Fri, 15 Nov 2019 19:45:34 +0000 X-Inumbo-ID: 6d40f128-07e0-11ea-b678-bc764e2007e4 Received: from mail-qk1-x741.google.com (unknown [2607:f8b0:4864:20::741]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 6d40f128-07e0-11ea-b678-bc764e2007e4; Fri, 15 Nov 2019 19:45:07 +0000 (UTC) Received: by mail-qk1-x741.google.com with SMTP id 205so9066761qkk.1 for ; Fri, 15 Nov 2019 11:45:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=C3RsL6LRs97DifodRCcEmAhXL6aDmbBJ1oLecoxp4fc=; b=oSOHWPurQzPaE1rkFXAS3ZR9QGmpEKN9QV9ocrB432AxeIw1+2YN7koYF6C4x3O6sp ctf3Q5A3KjSsfJtZPmH6pqXXfCCBXuVJ6yQJ6FjhroR79jn1OZnzH7vXEv6DkdvFSfmo g4YSSHiD61t1T8AJIPj97pIXnoW8CpRvHjeWoxXmfvHXUhgja5hE3GT3J/qSgtrpBXOy HhCetzlgjp1ijNmeH4thmH2o1GjfC2VwUy+qKT7bpxqRHtk5V8A/VNko2xGYlmZjhsWu 80OmbckTXHVYrxv+Lg6GGsSVEqtWEH9Ruoen/zpXJzZd/kIHSChRJv12OIQlj3zfqtMv nL2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=C3RsL6LRs97DifodRCcEmAhXL6aDmbBJ1oLecoxp4fc=; b=gzo4PZ35sJK3oem4Sa/IsrsGHFy1YGCpablH7+VjHViE7gUS3xUJ4MMVJVSBoW7TUc TVKXwR2fQ3k7nGS/I6ubTjdVq2yoN+ZZ/fG3DALg6TYGJV/ZmzIT9X55vNKps2dwVKdo 4a3Qi6todqB100tQkikgvvU4i9FSwc8sQmDy+l/DLWAfpD0aGQIMSlpc2BqnVTtj0yyP suNlqQvqE01mw4hVDxhyKzZouBOyLSR4T/zLUhBhLwaLBRRVafWzb8NcxrWzkA08zMcz TK2QSV1SWA+Xz0F1YmvGMZiTwmKBTBOkmxtIwOU0l8XYxDWYSu1qeqtOJqsSuU1MF8MD on/g== X-Gm-Message-State: APjAAAXSJsU4F88fsR0GOpBvrwzu04HyZgcfdJsIexY1e3YfhAPuPq1z uZMjN77DwStOxb0bL8TV2oIN8Pes X-Google-Smtp-Source: APXvYqxbzNIYsyknTd1QE1xFPF+aUKmrdGgqkMxEK04FSwOp3iAsh5y/t1eD23ppD8+Jl0ViE39K1A== X-Received: by 2002:a37:a392:: with SMTP id m140mr13862337qke.383.1573847106822; Fri, 15 Nov 2019 11:45:06 -0800 (PST) Received: from five.crux.rad.ainfosec.com (209-217-208-226.northland.net. [209.217.208.226]) by smtp.googlemail.com with ESMTPSA id y10sm4649679qkb.55.2019.11.15.11.45.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Nov 2019 11:45:06 -0800 (PST) From: Nick Rosbrook To: xen-devel@lists.xenproject.org Date: Fri, 15 Nov 2019 14:44:14 -0500 Message-Id: <64a78d4802d2aa4f43cf2959fa0d0d884631761e.1573840474.git.rosbrookn@ainfosec.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: References: MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v2 07/22] golang/xenlight: define Mac builtin type X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Nick Rosbrook , Ian Jackson , kerriganb@ainfosec.com, George Dunlap , Wei Liu Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" From: Nick Rosbrook Define Mac as [6]byte and implement fromC, toC, and String functions. Signed-off-by: Nick Rosbrook Reviewed-by: George Dunlap --- Changes in v2: - Fix the format string in String function to use %02x. - Use a value reciever for the toC function. tools/golang/xenlight/xenlight.go | 35 +++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/tools/golang/xenlight/xenlight.go b/tools/golang/xenlight/xenlight.go index 72afc3cf14..eb0d309543 100644 --- a/tools/golang/xenlight/xenlight.go +++ b/tools/golang/xenlight/xenlight.go @@ -181,6 +181,41 @@ func (d *Defbool) toC() (C.libxl_defbool, error) { return c, nil } +// Mac represents a libxl_mac, or simply a MAC address. +type Mac [6]byte + +// String formats a Mac address to string representation. +func (mac Mac) String() string { + s := "%02x:%02x:%02x:%02x:%02x:%02x" + opts := make([]interface{}, 6) + + for i, v := range mac { + opts[i] = v + } + + return fmt.Sprintf(s, opts...) +} + +func (mac *Mac) fromC(cmac *C.libxl_mac) error { + b := (*[6]C.uint8_t)(unsafe.Pointer(cmac)) + + for i, v := range b { + mac[i] = byte(v) + } + + return nil +} + +func (mac Mac) toC() (C.libxl_mac, error) { + var cmac C.libxl_mac + + for i, v := range mac { + cmac[i] = C.uint8_t(v) + } + + return cmac, nil +} + type Context struct { ctx *C.libxl_ctx logger *C.xentoollog_logger_stdiostream