From patchwork Tue Dec 10 15:47:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nick Rosbrook X-Patchwork-Id: 11282875 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 4428314BD for ; Tue, 10 Dec 2019 15:49:19 +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 202E5206D5 for ; Tue, 10 Dec 2019 15:49:19 +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="pTUHbIZ/" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 202E5206D5 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 1iehkR-00035F-7f; Tue, 10 Dec 2019 15:48:27 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iehkP-00034X-Ri for xen-devel@lists.xenproject.org; Tue, 10 Dec 2019 15:48:25 +0000 X-Inumbo-ID: 709bb30c-1b64-11ea-b6f1-bc764e2007e4 Received: from mail-qv1-xf42.google.com (unknown [2607:f8b0:4864:20::f42]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 709bb30c-1b64-11ea-b6f1-bc764e2007e4; Tue, 10 Dec 2019 15:47:59 +0000 (UTC) Received: by mail-qv1-xf42.google.com with SMTP id q19so4345845qvy.9 for ; Tue, 10 Dec 2019 07:47:58 -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=5Sxwv5A++XwWjW3r96jIpvbj5k3Ch0M30fjE7fzumV0=; b=pTUHbIZ/DpbwkzmQMz17B423imTwlhuSwOW23dDrhxWPxxYR7L7y8CMz0pr1I37unf 4DtiW4b9RmcuURRn+hn2Nb5fNQDdCfimhXEdYD9UHYuNObXCfagLPsKH/jzFmEm+8Og8 16vkqTYGnvmP4wJQomXPtVpOsuzMYN/Y3FeiTwRLq5t00OFgiOmz5q+fV8b7w0IU4jz2 REuw7/Z7b2OBPZA5SD1uS3ORmxylxZfOttnou9PEgfrXL8L8V5VbA6YdmOFnUTPN9H/q WWmbyNZBSpRUp/lOBJFx/fAug1DhLX1nWaG0YXkp2HiyzaUF8IWqb/GnVVxtjImN0VXS ycXw== 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=5Sxwv5A++XwWjW3r96jIpvbj5k3Ch0M30fjE7fzumV0=; b=GCPJ7UY3hbct6ZYKOE7arC1+EaD5mmM8sA1CL+ODVojSNIek5uRo3rMGX/Iz5kV3nc bNoCEXUI4CczjNHqJMAcTmS+QMGsaUpZCgpA9HHLRZVoAGbXzy2uvW6x9CSPlyU35Qf3 RACCIudHvLQzUaAZhavz0OHeOPXHuafq9X0pzTzAJRe4i4bo5xWc/MKJqNsiPlLrrx/l f46jDCorfvzsLKw7BsFrEVUUA6cTA0vDsYxUHbsqjjc+dq2+PWzk8ejT2Oi/1OVVRQgL PjBoTfUm3GYbGC9myvHhbhLdWzrXyfbjLfWrFcpQ4otwPBTBhIrjqrAdD8P43yR/7woj sb+w== X-Gm-Message-State: APjAAAWiK5H5vypBOzxdk6Q32LuvN0XBtMdxa3WyCnwbvlyIrgmU9fl+ L61jO3NS1aGsufbN9tn9bkEhNcOJ X-Google-Smtp-Source: APXvYqwK2pN/734YUERX1Hy9tqF2dVHK62qvXujL4uGZLiL2bKMtog0QHdO/rwqqjQaBI47C9hJBnQ== X-Received: by 2002:a05:6214:983:: with SMTP id dt3mr29504946qvb.145.1575992878193; Tue, 10 Dec 2019 07:47:58 -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 m29sm1247848qtf.1.2019.12.10.07.47.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Dec 2019 07:47:57 -0800 (PST) From: Nick Rosbrook To: xen-devel@lists.xenproject.org Date: Tue, 10 Dec 2019 10:47:22 -0500 Message-Id: <7de569cbacb5d9869ee657bd1ae3bc7c6fe49b1a.1575990937.git.rosbrookn@ainfosec.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: References: MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v3 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. Changes in v3: - Iterate over the indirect of mac instead of creating a slice from the C type. --- tools/golang/xenlight/xenlight.go | 33 +++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/tools/golang/xenlight/xenlight.go b/tools/golang/xenlight/xenlight.go index 72afc3cf14..17d146771e 100644 --- a/tools/golang/xenlight/xenlight.go +++ b/tools/golang/xenlight/xenlight.go @@ -181,6 +181,39 @@ 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 { + for i := range *mac { + mac[i] = byte(cmac[i]) + } + + 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